0

I'd like to get transaction info like sender and receiver address etc. by sending transaction hash as a parameter.

I did found "api.rpc.eth.getTransactionByHash" and tried to pass the hash but it was giving me "TypeError: api.rpc.eth.getTransactionByHash is not a function" error.

Here is my code:

const dotAddress = async () => {
  const wsProvider = new WsProvider("wss://rpc.polkadot.io");
  const api = await ApiPromise.create({ provider: wsProvider });
  const result = api.rpc.eth.getTransactionByHash(
    "0x334cdf788cd4449139ce7dc83bf448b5ef2addb88bf6b642ac43880137e75387"
  );
  console.log(result);
};

Any help appreciated, thank you!

3
  • 1
    The API will decorate the endpoints based on what is available on the node, e.g. rpc_methods and in the runtime metadata. Polkadot is not an ETH-compatible chain, it doesn't have the Frontier pallet. The eth.* namespace will only be available on chains with Frontier.
    – Jaco
    May 20, 2022 at 9:58
  • So... Is there any endpoints on polkadot chain which returns me transaction summary? I digged into documentation but couldn't find anything related. By the way thank you for your explanation Jaco!
    – korimusk
    May 20, 2022 at 11:06
  • In Substrate, transaction hashes are not unique, there is no RPC to retrieve by tx hash. Here is a link to the Polkadot wiki that explains the non-uniqueness of transaction hashes.
    – Jaco
    May 20, 2022 at 13:46

1 Answer 1

2

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 look them up that way.

Also note that transaction hash is not a unique identifier for a state transition (although is a unique identifier for a specific set of instructions and account context).

2
  • How can I index transactions from block? I tried api.query.transactionStorage.transactions(blockNumber), I am getting error. It seems transactionStorage is undefined
    – Heindrick
    Jun 30, 2022 at 15:02
  • If it is undefined, it means it is not exposed in the runtime, i.e. there is no pallet for this. The getBlock RPC returns the full block, based on hash (with the extrinsics included)
    – Barto
    Jul 13, 2022 at 7:24

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.