Skip to main content
11 votes
Accepted

Should events only be emitted in extrinsics?

Yes it is okay, and yes it definitely makes sense. The most common example of this pattern can be found in the Balances pallet, where Balances events are emitted every time the Currency trait is ...
Shawn Tabrizi's user avatar
  • 16.3k
11 votes
Accepted

Are there any event patterns for pallets to communicate within the runtime?

Events are really for the communication of state-transitions which happen on-chain to logic or services off-chain which would like to know when such a transition happens. They're not designed to be ...
Gav's user avatar
  • 2,681
8 votes

How to decode ink smart contract call and event data?

Having this data in hex format, you can decode it using cargo-contract command line utility simply like this (run from the contract src folder): cargo contract decode -d <data_hex_string> -t ...
Alexander Gryaznov's user avatar
7 votes

How to verify upward teleport on Relay Chain?

We have built this tool to find XCM events cross different chains https://parachain-utilities.vercel.app/xcm Code: https://github.com/AcalaNetwork/parachain-utilities/blob/...
Bryan Chen's user avatar
7 votes
Accepted

Which data to put in a Pallet Event?

For Substrate events are also "expensive". Events are in the state of each block. This means that archive nodes for example need to store all events of all blocks that ever happened. So, if ...
bkchr's user avatar
  • 11.8k
6 votes
Accepted

Browse events in Polkadot.js/api

For events (or any queries) at a specific point in the chain - // Get an API decorated at a specific point. This will - // - connect // - retrieve the metadata // - decorate the API based on ...
Jaco's user avatar
  • 5,985
6 votes
Accepted

How to parse/match a specific frame_system event?

The code removed in this PR is exactly what you need to do. Trying to translate it into your case would yield: #[pallet::hooks] impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet&...
kianenigma's user avatar
  • 2,864
5 votes

How to decode ink smart contract call and event data?

Typically all data is SCALE encoded for Substrate. You need to decode and parse the result into something human readable, like is done on the contracts-ui from the contracts-ui github and documented ...
Nuke's user avatar
  • 1,852
5 votes
Accepted

Correlate events with extrinsics in a utility.batch call in Polkadot

The utility.batch call emits events which allow you to organize which extrinsic events are coming from each extrinsic. Between each call, you should see an Event::ItemCompleted after an extrinsic as ...
Shawn Tabrizi's user avatar
  • 16.3k
5 votes
Accepted

Event type & Call type

Indeed, this is where Macro magic is happening. These Event and Call types are coming from construct_runtime!, and is generating an "outer enum" which collects all the events and calls from ...
Shawn Tabrizi's user avatar
  • 16.3k
4 votes

Filter events for specific account in Polkadot.js/api

The events are stored on chain as a Vec<EventRecord> - this means that when you make a query (either for latest or for a specific blockHash), that you would get set for that specific block. The ...
Jaco's user avatar
  • 5,985
4 votes
Accepted

Events in Polkadot.js/api

The api.event.<pallet>.<event>.is(Event) is not used to create an event, rather it is used to check if an emitted event is of a specific type, returning true if this is the case. ...
Jaco's user avatar
  • 5,985
4 votes
Accepted

Decoding events with Rust

There's two ways of decoding events in rust: statically typed and dynamically typed. Statically you can use subxt to decode events from this SCALE encoding - it's done here for example. Basically ...
Squirrel's user avatar
  • 3,901
4 votes

How to verify upward teleport on Relay Chain?

This is currently fiddlier than it needs to be. There will be a Balances.Deposit event citing the credited account (along with the normal XCM stuff, like Xcm.UpwardMessageProcessed), but for now you ...
dvdplm's user avatar
  • 401
4 votes

error[E0599]: no function or associated item named `events` found for struct `frame_system::Pallet` in the current scope

We have specifically removed access to the Events storage item in frame_system because it could cause the user to read a huge amount of storage, and the events storage is only meant to be read offline....
Shawn Tabrizi's user avatar
  • 16.3k
4 votes

Are there any event patterns for pallets to communicate within the runtime?

There are ways for pallets to communicate in the runtime, although I wouldn't use events for this (events are stored in an overlay that gets applied to storage at the end of the block (in ...
joepetrowski's user avatar
  • 2,975
4 votes
Accepted

Problem running assert_last_event in tests.rs

I believe the problem here is small and easy to miss. Substrate chains do not emit events when the block number is 0. This is to avoid hundreds or even thousands of events being generated in the ...
Shawn Tabrizi's user avatar
  • 16.3k
4 votes

How to parse/match a specific frame_system event?

@kianenigma, thanks for you extended and detailed answer. There was just one small missing piece. I had to setup the TryInto<Event<Self>> to the #[pallet::config] macro or otherwise your ...
Pablo Buitrago's user avatar
4 votes
Accepted

Emiting events does not work with cross contract calling

It is known issue, should be fixed with refactored events.
Green Baneling's user avatar
4 votes

How to save decoded events using polkadot.js?

All you want to do is have the data available outside the callback. So just set it to some variable - let decoded = null function setDecoded (value) { decoded = value } contract.tx .method({ ...
Barto's user avatar
  • 584
4 votes

Large event payloads unsafe?

Substrate will, by default, store every event in a block in a storage value Event of type Vec in the system module, which involves reading & writing this full vector each time, as explained here ...
bkchr's user avatar
  • 11.8k
4 votes

How to query events?

You can do frame_system::Pallet::<T>::events() to fetch all the events emitted. Example If you are working with mock runtime then you can directly use System::events() (System being the ...
AKASH S M's user avatar
4 votes

Event encoding in substrate pallet

Yes, event name is superficial. What actually matters is how the pallet event is encoded into bytes. Pallet events are encoded such that the first byte represents the pallet index, and the second byte ...
Shawn Tabrizi's user avatar
  • 16.3k
3 votes

What's the Substrate's equivalent of receipts in Ethereum?

Practically speaking, events are what you are looking for. It is up to the pallet implementation to define and emit these in a way that is useful for end consumers, like for use case. If there is ...
Nuke's user avatar
  • 1,852
3 votes

Should events only be emitted in extrinsics?

There are also examples for events that are not tied to extrinsics, or rather those submitted much earlier. For instance the scheduler can perform an upgrade for a runtime approved via democracy. In ...
Luna's user avatar
  • 321
3 votes

How to build prefixed key for rocksdb

If you want to pull a specific storage item from rocksdb, it requires traversing the patricia trie in order to find the key that you want. This can become complicated quickly, and is generally a slow ...
insipx's user avatar
  • 373
3 votes
Accepted

How can I access custom pallet Event data in a test?

Here is a working example of a test using the pallet-template from the substrate-node-template: #[test] fn stackexchange_question() { new_test_ext().execute_with(|| { // To emit events, we ...
Shawn Tabrizi's user avatar
  • 16.3k
3 votes

How can a recoverable account get notified when someone is initiated a recovery for it?

If you want to notify the user exactly when a recovery process for their account has started, there will be a Pallet Event RecoveryInitiated when the recovery process has started, which can be ...
Shawn Tabrizi's user avatar
  • 16.3k
3 votes

Why are events stored?

The idea behind writing the events into the storage is to ensure they influence the state root in the block and ensure that events are stored somewhere for retrieval. The fact that the events are ...
pepyakin's user avatar
  • 2,194
3 votes

How to save decoded events using polkadot.js?

This is a good question. From all the examples that I have seen, it looks like you may have to have your program logic inside the signAndSend. Also, a note that contract.tx.method({ ...
Bruno's user avatar
  • 8,455

Only top scored, non community-wiki answers of a minimum length are eligible