ContractEmitted

Event v334 → current #3

Emitted when a contract emits a custom event during execution.

View events on chain
Useful for: developersanalytics

The Big Picture

Contracts can emit their own events. This wraps those custom events. The data field contains contract-defined data that must be decoded using the contract's ABI.

Use Cases

  • Monitor contract-specific events
  • Build contract-aware indexers
  • Debug contract execution

From Chain Metadata

A custom event emitted by the contract.

Triggers

Preconditions

  • Contract is executing
  • Contract calls seal_deposit_event

Effects

Storage Modified

Postconditions

  • Custom event data recorded

Side Effects

  • Gas consumed for event emission

Event Data

#NameTypeDescription
0
contract
AccountId Contract that emitted this custom event (hex -> SS58)
1
data
Vec<u8> VecContract-defined event data (decode with contract ABI)

Code Examples

import { ApiPromise, WsProvider } from "@polkadot/api";
import { stringCamelCase } from "@polkadot/util";

const provider = new WsProvider("wss://entrypoint-finney.opentensor.ai:443");
const api = await ApiPromise.create({ provider });

// Subscribe to ContractEmitted events
api.query.system.events((events) => {
  events
    .filter(({ event }) =>
      event.section === stringCamelCase("Contracts") &&
      event.method === "ContractEmitted"
    )
    .forEach(({ event }) => {
      console.log("ContractEmitted:", event.data.toHuman());
    });
});

Runtime Info

Pallet Index
29
Event Index
3
First Version
v334
Current Version
v393