Skip to content

Instantly share code, notes, and snippets.

@yornaath
Created May 30, 2022 14:36
Show Gist options
  • Save yornaath/ba5eedc4d1ca82654e117f459efba6de to your computer and use it in GitHub Desktop.
Save yornaath/ba5eedc4d1ca82654e117f459efba6de to your computer and use it in GitHub Desktop.
Substrate/Polkadot.js - get extrinsics at event
export const extrinsicsAtEvent = (
events: Vec<EventRecord>,
block: SignedBlock,
filter?: {
method?: string;
}
) => {
return block.block.extrinsics.filter((ex, index) =>
Boolean(
events.find(
(event) =>
event.phase.isApplyExtrinsic &&
event.phase.asApplyExtrinsic.eq(index) &&
(!filter?.method || ex.method.method.toString() === filter.method)
)
)
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment