Set the Hook State for a given key and value


  • Read a 32 byte Hook State key from the kread_ptr
  • Read an arbitrary amount of data from read_ptr (the value)
  • Update the Hook State key with the value


int64_t state_set (
    uint32_t read_ptr,
    uint32_t read_len,
    uint32_t kread_ptr,
    uint32_t kread_len  


#define SBUF(str) (uint32_t)(str), sizeof(str)
if (state_set(SBUF(vault), SBUF(vault_key)) < 0)
        rollback(SBUF("Error: could not set state!"), 1);


read_ptruint32_tPointer to the data (value) to write into Hook State.
If this is 0 (null) then delete the data at this key. May be null.
read_lenuint32_tThe length of the data.
If this is 0 (null) then delete the data at this key. May be null.
kread_ptruint32_tA pointer to the Hook State key at which to store the value.
kread_lenuint32_tThe length of the key. (Should always be 32.)



Xrpl sets internally a maximum hook data size. At time of writing and for public testnet this is hard coded at 128 bytes, however in future it will be a validator-votable number.

Return Code

int64_tThe number of bytes written to Hook State (the length of the data.)

If negative, an error:
- pointers/lengths specified outside of hook memory.

- kread_len was greater than 32, or
- read_len was greater than the maximum hook data size.

- kread_len was 0.