2

I'm trying to make my very first indexer. I want to pull the caller (initiator's address) of a runtime system.remark, as well as the block number.

What is the best way to do this via hooking into the runtime modules.

2
  • By caller, do you mean the EOA which send this transaction ? Apr 18 at 8:12
  • yes, that is correct.
    – rarara
    Apr 19 at 2:13

1 Answer 1

4

the ID of the account that triggered the extrinsic is present in the ExtrinsicHandlerContext, under extrinsic.signer. You can simply do this to obtain it:

ctx.extrinsic.signer

the block number is available in the block field of the ExtrinsicHandlerContext as height:

ctx.block.height

You could also hook to the system.Remarked event, instead of the system.remark call.

https://polkadot.subscan.io/event?module=System&event=Remarked

The Event should follow the call, if I am not mistaken, and, as a bonus, it reports the sender field as one of the Event's arguments. Subsquid's typegen generates this wrapper for it:

export class SystemRemarkedEvent {
  constructor(private ctx: EventContext) {
    assert(this.ctx.event.name === 'system.Remarked')
  }

  /**
   *  On on-chain remark happened. \[origin, remark_hash\]
   */
  get isV2030(): boolean {
    return this.ctx._chain.getEventHash('system.Remarked') === 'e54ae910805a8a9413af1a7f5885a5d0ba5f4e105175cd6b0ce2a8702ddf1861'
  }

  /**
   *  On on-chain remark happened. \[origin, remark_hash\]
   */
  get asV2030(): [Uint8Array, Uint8Array] {
    assert(this.isV2030)
    return this.ctx._chain.decodeEvent(this.ctx.event)
  }

  /**
   * On on-chain remark happened.
   */
  get isV9160(): boolean {
    return this.ctx._chain.getEventHash('system.Remarked') === 'c58b73482fe762a6dcca2f35266f0d1739333312cf7a50eea55c666d0cda6101'
  }

  /**
   * On on-chain remark happened.
   */
  get asV9160(): {sender: v9160.AccountId32, hash: v9160.H256} {
    assert(this.isV9160)
    return this.ctx._chain.decodeEvent(this.ctx.event)
  }

  get isLatest(): boolean {
    deprecateLatest()
    return this.isV9160
  }

  get asLatest(): {sender: v9160.AccountId32, hash: v9160.H256} {
    deprecateLatest()
    return this.asV9160
  }
}

As for the block number, it's even easier, you can get it like this:

ctx.event.blockNumber
1
  • Thanks, quick and easy!
    – rarara
    Apr 19 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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