2

I am a developer integrating Polkadot JS to my app. I am creating an offline transaction which I am sending via the Polkadot Api RPC. In return I get the txid, but it does not help me to retrieve the transaction once it is mined. I need to get the block index and the extrinsing index in the block that the transaction will be mined. I am using the HTTP provider, the websoccet will not work for me. Can you guide me in the right direction?

Best regards!

2
  • 1
    I am not sure how long the HTTP will still work. Why can you not use WS? Normally you would use the signAndSend which returns a promise. Nov 24, 2022 at 15:37
  • I am not using signAndSend because I dont want to share the private keys. I want to use HTTP because it is stateless. Even if I use websocket how would that benefit me? Nov 24, 2022 at 17:04

1 Answer 1

1

If you just have transaction hash, note that is not a unique identifier for a transaction in Polkadot, check this answer.

What you can do is a function with PolkadotJS that is listening to the events to see where your transactions has been included.

Simple script:

// Subscribe to system events via storage
api.query.system.events((events) => {
  console.log(`\nReceived ${events.length} events:`);

  // Loop through the Vec<EventRecord>
  events.forEach((record) => {
    // Extract the phase, event and the event types
    const { event, phase } = record;
    const types = event.typeDef;
    console.log(event.toHuman());
  });
});

If as Oliver suggest you use signAndSend is easier, check this answer on StackExchange

1
  • Using the events is not an option for me nor sharing the private key / mnemonic of the wallet. Is there any way that with the transaction hash I can receive all transactions with this hash? Nov 25, 2022 at 13:03

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.