> For the complete documentation index, see [llms.txt](https://thryec.gitbook.io/dev-compedium/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thryec.gitbook.io/dev-compedium/near/rust-contracts/events-and-meta-transactions.md).

# Events & Meta-transactions

### Events&#x20;

The Events format is a standard interface for tracking contract activity.&#x20;

Events use the standard logs capability of NEAR. Events are log entries that start with the `EVENT_JSON:` prefix followed by a single valid JSON string.

JSON string should have the following interface:

```rust
// Interface to capture data about an event
// Arguments
// * `standard`: name of standard, e.g. nep171
// * `version`: e.g. 1.0.0
// * `event`: type of the event, e.g. nft_mint
// * `data`: associate event data. Strictly typed for each set {standard, version, event} inside corresponding NEP
interface EventLogData {
    standard: string,
    version: string,
    event: string,
    data?: unknown,
}
```

Thus, to emit an event, you only need to log a string following the rules above. Here is a barebones example using Rust SDK `near_sdk::log!` macro (security note: prefer using `serde_json` or alternatives to serialize the JSON string to avoid potential injections and corrupted events):

```rust
use near_sdk::log;

// ...
log!(
    r#"EVENT_JSON:{"standard": "nepXXX", "version": "1.0.0", "event": "YYY", "data": {"token_id": "{}"}}"#,
    token_id
);
// ...
```

**Valid event logs**

```bash
EVENT_JSON:{
    "standard": "nepXXX",
    "version": "1.0.0",
    "event": "xyz_is_triggered",
    "data": {
        "triggered_by": "foundation.near"
    }
}
```

**Invalid event logs**&#x20;

* Two events in a single log entry (instead, call `log` for each individual event)
* Invalid JSON data&#x20;
* Missing required fields `standard`, `version` or `event`

**Drawbacks**

There is a known limitation of 16kb strings when capturing logs. This impacts the amount of events that can be processed.

### Meta-Transactions&#x20;

In-protocol meta transactions allowing for third-party account to initiate and pay transaction fees on behalf of the account.

Changes to protocol are required:

* New Action kind: `DelegateAction(receiver_id, Action, signer_pk, signature)`
* On conversion to Receipt, such action is sent as `DelegateAction` to the `receiver_id`.
* On processing Receipt, it verifies the `signature` over the given account and `signer_pk`. Unwraps into `receiver_id: AccountId`, `action: Action` inside into new Receipt with given `receiver_id` and `action`. This means that `predeccessor_id` of such action has been overriden.

#### Drawbacks

Increases complexity of the NEAR's transactional model.

Meta transactions take an extra block to execute, as they first need to be included by the originating account, then routed to the delegate account and only after that to the real destination.

Delegate actions are not programmable as they require having signatures. Original proposal contained a new `AccessKey` kind that would support programmable delegated actions. On the other hand, that would be limiting without progamability of smart contracts, hence that idea evolved into [Account Extensions](https://github.com/nearprotocol/neps/pull/0000).

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://thryec.gitbook.io/dev-compedium/near/rust-contracts/events-and-meta-transactions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
