Skip to main content
Version: 4.22.0

Reading emitted events

Starknet events

A contract may emit events throughout its execution. Each event contains the following fields:

from_address: address of the contract emitting the events
keys: a list of field elements
data: a list of field elements

The events are stored in a block on the blockchain.

Events in the Cairo code

You have to analyze the Cairo code of your smart contract, to recover the list of data emitted by the event :

func log_data(d1: felt, d2: felt, d3: felt) {

func my_func{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() {
log_data.emit(start_field, high_range, status_prog);
return ();

Here, we can see that the event will store 3 felts.

Once compiled, this code will generate an abi file containing :

"data": [
{"name": "d1", "type": "felt"},
{"name": "d2", "type": "felt"},
{"name": "d3", "type": "felt"},
"keys": [],
"name": "log_data",
"type": "event",

Recover the event data

Once the my_func is invoked, the event is stored in the blockchain and you get in return the transaction hash.

const resu = await myTestContract.invoke("my_func");
const txReceiptDeployTest = await provider.waitForTransaction(resu.transaction_hash);

In Typescript, you have to change a little the code :

import { number, InvokeTransactionReceiptResponse } from "starknet";

const resu = await myTestContract.invoke("my_func");
const txReceiptDeployTest: InvokeTransactionReceiptResponse = await provider.waitForTransaction(resu.transaction_hash);
console.log("events =",;

Now, you have all the events of the block. Here, we have 2 events - the last one contains our data :

[Object: null prototype] {
data: [
from_address: '0x465e68294995849bd00ac9f6ad4ee12be3cec963d8fe27172a1eadda608c110',
keys: [
[Object: null prototype] {
data: [
from_address: '0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
keys: [

Use the contract deployment address, to filter the events and read the data from your smart contract :

const event =
(it) => number.cleanHex(it.from_address) === number.cleanHex(testContractAddress)
) || {data: []};

const eventD1 =[0];
const eventD2 =[1];
const eventD3 =[2];