3

When I submit a transation using the polakdot-js-api I get that the transaction is included in block number and I also receive the extrinsic hash

```*Tx included at block hash 0x9225abf7cb9241f543f629c4277cb7799ab90e557af8f4d17201ae1f2d625765*
*Tx hash: 0x3e2f84e2f46cb82a2491fa772d66127ec8c8c00ce15a0bfc65be31fcf400b7a5*```

But is it possible for me to get the data that is submitted in that particular transaction through this extrinsic-hash that I got from the above transation?

1 Answer 1

6

There are a couple ways you could work with that. If you have the extrinsic hash and the block number than you could something like this:

const exampleBlockNumber = 7200920
const blockHash = await api.rpc.chain.getBlockHash(exampleBlockNumber);
const signedBlock = await api.rpc.chain.getBlock(blockHash);
const extrinsicHash = "0xeb8f2a5af4a82a237e7e270ed6bd51ce82bb9253802259fd0fdb24212fe65260"
signedBlock.block.extrinsics.forEach(async (ex, index) => {
    if (extrinsicHash === ex.hash.toHex()) {
        console.log(index, ex.toHuman());
        const { method: { args, method, section } } = ex;
        console.log(`${section}.${method}(${args.map((a) => a.toString()).join(', ')})`);
    }
});

For this specific example you would get this output:

1 {
  isSigned: true,
  method: {
    args: { dest: [Object], value: '39.5536 DOT' },
    method: 'transfer',
    section: 'balances'
  },
  era: { MortalEra: { period: '64', phase: '18' } },
  nonce: '0',
  signature: '0x56344710ae648a1da40e2c1a1159c73fdbd7d522af01f1fd330fb6bedc4db615ca983d69fcf7cdf7376ab59fd4c492a711cc64bba48d6ae23762d95176071a0c',
  signer: { Id: '13a9ccJQrJZdLsdisnL31uuApQmNfGd3d3fmGdqLPiBiW8jP' },
  tip: '0'
}
balances.transfer(13Hwdzi6jkXtBWTSU5de5gC93hDog23pdqd59SPZ7s9zXVNL, 395536044985)
4
  • yeh it worked. thanks
    – kroos47
    Mar 9, 2022 at 7:19
  • Hey what if I have only the extrinsic hash and not the block number?
    – Non-named
    Mar 31, 2022 at 9:21
  • @Bukks no you need both ext_hash and block number. See this substrate.stackexchange.com/questions/2536/…
    – kroos47
    Jun 1, 2022 at 11:58
  • is there any property in ex to get result of transfer ?
    – kunal
    Jun 14, 2022 at 9:35

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.