2

I have stored an information on chain and I want to access that information using RPC call.

I used the following code and provided the hash created.

const signedBlock = await api.rpc.chain.getBlock(blockHash);

How can I retrieve/see the data I uploaded to that block?

If have uploaded "string" in that block. How can i get it back as "string" by providing the block hash

3
  • What do you mean you have uploaded "string" in that block? Have you executed an extrinsic and you want to see the storage? Please add more info.
    – Bruno
    Commented Dec 16, 2022 at 19:47
  • "string" is any value stored in the transaction. Consider that i store "abcd" in a trasaction and i have transaction hash and block hash. How can i retrieve data stored using them? Commented Dec 16, 2022 at 21:40
  • So, what you have is basically a system::remark extrinsic? in that case you can iterate and find the right extrinsic via signedBlock.block.extrinsics.
    – kianenigma
    Commented Dec 18, 2022 at 14:17

1 Answer 1

1

With your instruction

const signedBlock = await api.rpc.chain.getBlock(blockHash);

You have all the information on the Block, you can get now all the extrinsics from the block

signedBlock.block.extrinsics.forEach((ex, index) => {
    console.log("---extrinsic----");
    console.log(ex.toHuman());
});

This will print all the extrinsics on the block and the information, you will have to find yours. If you know the pallet of your extrinsic you can filter .

const { method: { args, method, section } } = ex;
const pallet = ex.method.section;

Or if you know the Extrinsic ID you can filter by the extrinsic ID to get it:

const extrinsicId = signedBlock.block.header.number + "-" + index
1
  • yes it worked some where closer. I can see the data that i am looking for and ican extract it Commented Dec 22, 2022 at 12:32

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.