6

There's some great examples of how to use subxt to listen to all events.

Polkadot-js events screen seem to show events grouped by the extrinsic that created them. Can I do the same in rust?

(if not subxt is there an alternative way?)

1 Answer 1

7

The logic in subxt will map through in a similar way.

The EventRecord struct contains a Phase enum where ApplyExtrinsic(u32) refers to the index of the extrinsic in the block.

So the way to map it is -

  1. If phase is not ApplyExtrinsic, it doesn't map to a transaction, e.g. it is a system event
  2. If the phase is ApplyExtrinsic, get the index from this value
  3. Map the extracted index to the extrinsic, as found in the block
3
  • Ah, that's what that number is in phase. The u32 is the extrinsic id (the transaction id). Great, now I just need to look up lots of extrinsic's by id...
    – Squirrel
    Apr 27, 2022 at 7:33
  • Ah subxt can listen to blocks: client.rpc().subscribe_blocks() (but maybe we need to add that not uncommon usecase to the subxt examples!)
    – Squirrel
    Apr 27, 2022 at 8:02
  • Thank you so much for getting me unstuck!
    – Squirrel
    Apr 27, 2022 at 8:18

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.