0

I want to know how I can get list of transactions and transactions info for specific wallet address in polkadot.js/api, especially for kusama.

const provider = new WsProvider("wss://kusama-rpc.polkadot.io");
const api = await ApiPromise.create({ provider });
const response = await api.rpc.eth.getTransactionByHash(hash);

I am not sure if above code is for transactions, however it is not running and cause error.

UnhandledPromiseRejectionWarning: TypeError: api.rpc.eth.getTransactionByHash is not a function

How can I get transactions from wallet address in polkadot.js/api?

3
  • 4
  • It doesn't give answer for my question. I commented in above question, how can I get transactions from block? Or is there any other solution?
    – Heindrick
    Jun 30, 2022 at 15:04
  • I believe both links by @Jaco are answering your question: The node itself doesn't index all transactions, it just stores blocks and states. You should fetch all blocks yourself and index transactions. If you want to fetch transactions from a block you can use API Sidecar to do this: Have a look at wiki.polkadot.network/docs/… for more details
    – Iker
    Jul 1, 2022 at 7:40

1 Answer 1

6

To answer your comment around block-by-hash (there are no account -> transaction mappings on the RPCs, as per the linked answers in the comments above) -

You can use the getBlock RPC call. Since you are using the JS API based on your example -

// retrieve the block by hash, API decodes extrinsics
const signedBlock = await api.rpc.chain.getBlock("0x...blockHash here...")

// loop through extrinsics
for (let i = 0; i < signedBlock.block.extrinsics.length; i++) {
  const x = signedBlock.block.extrinsics[i];

  console.log(`
    isSigned=${x.isSigned},
    pallet=${x.method.section},
    method=${x.method.method}
  `)
}
2
  • Thanks for your answer. I was able to run your code. However, it doesn't give transaction information. Like transaction amount, type, fee etc. How can I get it?
    – Heindrick
    Jul 1, 2022 at 15:41
  • Those are all part of the arguments - x.args in the naming above. Jul 3, 2022 at 6:40

Your Answer

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

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