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> Vec Contract-defined event data (decode with contract ABI)

Code Examples

import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443

const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);

// Subscribe to ContractEmitted events
client.finalizedBlock$.subscribe(async (block) => {
  const events = await api.event.Contracts.ContractEmitted.get(block.hash);
  for (const evt of events) {
    console.log("ContractEmitted:", evt.payload);
  }
});

Runtime Info

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