1

I'm new to polkadot. I am working on checking received transactions to my wallets. I have used below code & able to get hash, from, to & amount etc. but I am not able to get result & fee of received balance transfer in ex in below code

const signedBlock = await api.rpc.chain.getBlock(blockHash);
    signedBlock.block.extrinsics.forEach((**ex**, index) => {
        if(ex.method.section === 'balances' && ex.method.method === 'transfer'){
            console.log(`Tx[${ex.hash.toString()}] : Amount[${ex.args[1].toString()}] sent from[${ex.signer.toString()}] to[${ex.args[0].toString()}]`);
        }
   });

Please help me. Thanks.

2 Answers 2

2

The polkadot-js API docs has some cookbook examples of this -

1
  • Thanks. cookbook example solved my problem.
    – kunal
    Jun 14 at 17:38
2

The block body itself is just an array of extrinsics (in this context, function calls), but since the block is constructed prior to its execution, it cannot include the results of calling those functions. For that, you need to look into events, which get written to state at the end of block execution.

If you're monitoring a wallet's deposits, we have a special guide to that on the Polkadot Wiki.

Further, I'd recommend that you not implement this yourself, and just use Substrate API Sidecar. Calling GET block will give you all the info you are looking for. However, if you do want to go for it, I'd still use Sidecar as a reference, e.g. how it gets blocks.

1
  • Thanks for reply.I am using event code.
    – kunal
    Jun 14 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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