Appearance
ledger_nonce
Summary. Write a unique 32-byte nonce derived from ledger and transaction context.
Signature.
c
int64_t ledger_nonce(uint32_t write_ptr, uint32_t write_len);Parameters.
| Name | Type | Description |
|---|---|---|
write_ptr | uint32_t | Destination buffer. |
write_len | uint32_t | Must be at least 32. |
Return value. Returns 32 (bytes written) on success. Errors: TOO_SMALL (-4) if write_len < 32; OUT_OF_BOUNDS (-1) for a bad buffer; TOO_MANY_NONCES (-12) on the 257th request in one execution.
Common failure patterns.
- Requesting a 257th nonce in one execution →
TOO_MANY_NONCES(the first 256 requests succeed). - A buffer shorter than 32 bytes →
TOO_SMALL.
Caveats / notes.
- Each call increments an internal counter and hashes ledger sequence, parent close time, parent hash, the transaction id, the counter, and the hook account, so successive nonces differ and are deterministic across validators.
- This is the general-purpose nonce; for emitting transactions use
etxn_nonce, which serves the emission machinery.
Minimal example.
c
uint8_t n[32];
ledger_nonce((uint32_t)n, 32);Related APIs. etxn_nonce, ledger_last_hash.