Skip to main content
Smart contracts can emit events — structured log messages that follow NEP-297 and are stored on-chain. Events allow indexers, frontends, and external services to track meaningful contract activity without parsing arbitrary log strings. Events are most useful when several contracts must report the same kind of activity in a standard format, as the FT and NFT standards do. If you only need to read the calls made to your own contract, an indexer can read their arguments directly from the transactions. See A contract is not a backend. An event is a log line prefixed with EVENT_JSON: followed by a JSON object with a fixed schema:

Defining and Emitting Events

The near-sdk provides a high-level macro-based API for defining and emitting events. Annotate an enum with #[near(event_json(standard = "..."))] and mark each variant with #[event_version("...")].
Call .emit() on an event variant to write it to the on-chain log:
The macro automatically serializes the enum variant to the EVENT_JSON: format and calls env::log_str under the hood.
You can emit multiple data entries in a single event by passing a Vec with more than one element. This keeps gas costs lower than emitting one event per entry.

Custom Events

You are not limited to standard NEP events. Define your own standard name for application-specific activity:

Standard Events (FT & NFT)

If you are implementing Fungible Tokens or Non-Fungible Tokens, the standard events are already defined:
  • NEP-141 (FT): ft_transfer, ft_mint, ft_burn — see the Fungible Token docs.
  • NEP-171 (NFT): nft_mint, nft_transfer, nft_burn — see the Non-Fungible Token docs.
Using the standard event names ensures compatibility with explorers and indexers that already know how to parse them.

Consuming Events with Indexers

Emitted events are stored as transaction logs on-chain and can be consumed by any indexer that listens for EVENT_JSON: prefixed log lines. See the indexing guide to choose a data source for consuming these events.