Events & Meta-transactions
Events
The Events format is a standard interface for tracking contract activity.
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:
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):
Valid event logs
Invalid event logs
Two events in a single log entry (instead, call
log
for each individual event)Invalid JSON data
Missing required fields
standard
,version
orevent
Drawbacks
There is a known limitation of 16kb strings when capturing logs. This impacts the amount of events that can be processed.
Meta-Transactions
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 thereceiver_id
.On processing Receipt, it verifies the
signature
over the given account andsigner_pk
. Unwraps intoreceiver_id: AccountId
,action: Action
inside into new Receipt with givenreceiver_id
andaction
. This means thatpredeccessor_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.
Last updated