1

Using py-substrate-interface to parse block data, we noticed that some events return None for the extrinsic_idx parameter.

Would someone please be so kind to explain why an event wouldn't have an extrinsic (idx) associated to it?

See below code and output for example:

Code:

from base64 import decode
from substrateinterface import SubstrateInterface

substrate = SubstrateInterface(
            url='wss://rpc.polkadot.io')

block_hash = substrate.get_block_hash(12449658)

test_block = substrate.get_block(block_hash=block_hash)

test_events = substrate.get_events(block_hash)

#visualising events in polkadot block 12449658
for idx,event in enumerate(test_events):
    decoded_event = event.decode()
    print("event_idx ",idx,
    "phase ",decoded_event['phase'],
    "module_id ",decoded_event['module_id'],
    "event_id ",decoded_event['event_id'],
    "extrinsic_idx", decoded_event['extrinsic_idx'])

Output:

event_idx  0 phase  Initialization module_id  ImOnline event_id  AllGood extrinsic_idx None
event_idx  1 phase  Initialization module_id  Staking event_id  EraPaid extrinsic_idx None
event_idx  2 phase  Initialization module_id  Balances event_id  Deposit extrinsic_idx None
event_idx  3 phase  Initialization module_id  Treasury event_id  Deposit extrinsic_idx None
event_idx  4 phase  Initialization module_id  Session event_id  NewSession extrinsic_idx None
event_idx  5 phase  ApplyExtrinsic module_id  System event_id  ExtrinsicSuccess extrinsic_idx 0
event_idx  6 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateIncluded extrinsic_idx 1
event_idx  7 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateIncluded extrinsic_idx 1
event_idx  8 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateIncluded extrinsic_idx 1
event_idx  9 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateIncluded extrinsic_idx 1
event_idx  10 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateIncluded extrinsic_idx 1
event_idx  11 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateIncluded extrinsic_idx 1
event_idx  12 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateIncluded extrinsic_idx 1
event_idx  13 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateIncluded extrinsic_idx 1
event_idx  14 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateIncluded extrinsic_idx 1
event_idx  15 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateIncluded extrinsic_idx 1
event_idx  16 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateBacked extrinsic_idx 1
event_idx  17 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateBacked extrinsic_idx 1
event_idx  18 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateBacked extrinsic_idx 1
event_idx  19 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateBacked extrinsic_idx 1
event_idx  20 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateBacked extrinsic_idx 1
event_idx  21 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateBacked extrinsic_idx 1
event_idx  22 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateBacked extrinsic_idx 1
event_idx  23 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateBacked extrinsic_idx 1
event_idx  24 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateBacked extrinsic_idx 1
event_idx  25 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateBacked extrinsic_idx 1
event_idx  26 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateBacked extrinsic_idx 1
event_idx  27 phase  ApplyExtrinsic module_id  ParaInclusion event_id  CandidateBacked extrinsic_idx 1
event_idx  28 phase  ApplyExtrinsic module_id  System event_id  ExtrinsicSuccess extrinsic_idx 1
event_idx  29 phase  Finalization module_id  Grandpa event_id  NewAuthorities extrinsic_idx None

1 Answer 1

2

Only the events in phase ApplyExtrinsic have an extrinsic index attached.
Everything that runs before is from on_initialize hooks and everything afterwards from on_finalize.
These always run in every block and cannot be triggered through an extrinsic, hence no index.

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.