getEvents - Stellar
Example code for the getEvents JSON-RPC method. Complete guide on how to use getEvents JSON-RPC in GetBlock Web3 documentation.
This method returns contract events from the Stellar network based on filter criteria.
Parameters
startLedger
integer
The first ledger to include
filters
array
(optional) Array of event filters
pagination
object
(optional) Pagination options
Filter Object:
type
string
Event type: "contract", "system", or "diagnostic"
contractIds
array
Array of contract IDs to filter
topics
array
Array of topic filters
Request
curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "getEvents",
"params": {
"startLedger": 2539600,
"filters": [
{
"type": "contract",
"contractIds": ["CCJZ5DGASBWQXR5MPFCJXMBI333XE5U3FSJTNQU7RIKE3P5GN2K2WYD5"]
}
],
"pagination": {
"limit": 100
}
},
"id": "getblock.io"
}'import axios from 'axios';
const data = JSON.stringify({
"jsonrpc": "2.0",
"method": "getEvents",
"params": {
"startLedger": 2539600,
"filters": [
{
"type": "contract",
"contractIds": ["CCJZ5DGASBWQXR5MPFCJXMBI333XE5U3FSJTNQU7RIKE3P5GN2K2WYD5"]
}
],
"pagination": {
"limit": 100
}
},
"id": "getblock.io"
});
const config = {
method: 'post',
url: 'https://go.getblock.io/<ACCESS-TOKEN>/',
headers: {
'Content-Type': 'application/json'
},
data: data
};
axios(config)
.then(response => console.log(JSON.stringify(response.data)))
.catch(error => console.log(error));Response
Response Parameters
events
array
Array of event objects
type
string
Event type
ledger
integer
Ledger sequence number
contractId
string
Contract that emitted the event
topic
array
Event topics (base64 XDR)
value
string
Event value (base64 XDR)
latestLedger
integer
Latest available ledger
Use Case
The getEvents method is essential for:
Smart contract event monitoring
DApp state synchronization
Event-driven applications
Activity tracking
Notification systems
Analytics and indexing
Error Handling
403
Forbidden
Missing or invalid ACCESS-TOKEN
-32602
Invalid params
Invalid filter or pagination parameters
Last updated
Was this helpful?