I'm porting a script from TypeScript using the Polkadot.JS/api to Rust using Subxt.

    let query = polkadot::storage().referenda().referendum_info_for_root();

    let mut results = api.storage().at_latest().await?.iter(query,10).await?;

    while let Some((key, value)) = results.next().await? {

With reference to the above, I'm having trouble getting the referendum id from the key. Within my TypeScript code I would use something like key.toHuman()[0].


  • What kind of trouble did you encounter?
    – AurevoirXavier
    Commented Sep 25, 2023 at 2:52
  • You dont have to use toHuman() here, have you tried to print the key and the value?
    – Alex Bean
    Commented Sep 26, 2023 at 7:47

1 Answer 1


I got some help from @Turboflakes the developer behind CrunchBot. He referred me to an article and supported with some code to help 'decode' the Storage key.


Within the while loop I use:


The function's details are:

pub fn get_ref_id_from_storage_key(key: Vec<u8>) -> u32 {
    let s = &key[key.len() - 4..];
    let v: [u8; 4] = s.try_into().expect("slice with incorrect length");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.