-1

enter image description here

Request RPC via http. How to obtain transaction results and transaction time.

Is there a friend who can give me some advice? thank you very much indeed

1
  • 5
    It sounds like you want to use a tool like Substrate Sidecar for what you are doing here. These properties are not easily accessible via RPC.
    – Shawn Tabrizi
    May 9, 2022 at 13:37

2 Answers 2

2

For the extraction of the timestamp, this has been answered elsewhere, aka it would the the timestamp of the block that the extrinsic was included in.

To check the status of the execution, you need to map the extrinsic to the events.

Like everything is Substrate (extrinsics, storage, errors) this all hangs off SCALE encoding and the information in the on-chain metadata, as retrieved via state_getMetadata. The metadata explicitly defines all the indexes, arguments and types for all of these.

The steps would be -

  • Get the storage for the events at the blockHash (on RPC this would be via state_getStorage with the encoded key for the system.events storage item)
  • Decode this SCALE result based on the event indexes and types in the metadata
  • Map the decoded events to the extrinsic - to do this, check the phase in the EventRecord, it should be ApplyExtrinsic(u32) where the u32 is the index of the extrinsic in the block
  • On these filtered events check for either System.ExtrinsicSuccess or System.ExtrinsicFailed
  • On failed extrinsics, the DispatchError -> Module will have the error indexes. You can map these using the error indexes from the on-chain metadata
2
  • public static void main(String[] args) { UInt32Reader reader = new UInt32Reader(); String str = "0x280402000b919bbc3b8001"; String replace = str.replace("0x", ""); ByteData readA = ByteData.from(replace); ScaleCodecReader codec = new ScaleCodecReader(readA.getBytes()); codec.hasNext(); Long read = codec.read(reader); System.out.println(read); }
    – Andy
    May 17, 2022 at 3:16
  • What kind of method is the timestamp problem? I tried several methods similar to the above, but I haven't got the timestamp yet
    – Andy
    May 17, 2022 at 3:17
1

Here you have a comprehensive guide to get the required (and other related) information by using Polkadot-js API:

https://polkadot.js.org/docs/api/cookbook/blocks/

In that guide, you have a section to see all the extrinsic information and another section to determine if an extrinsic succeeded/failed.

1
  • I know this, but my problem is to request RPC directly through HTTP. What you said won't help me
    – Andy
    May 18, 2022 at 6:50

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