Get all logs of a contract
Overview
The "Get all logs from a contract" API simplifies the process of retrieving event logs emitted by any smart contract. Unlike the traditional method of using eth_getLogs or eth_getFilterChanges and eth_newFilter in combination, which requires inefficiently polling through each block and filtering out non-relevant results, this API returns only the positive matches, saving time and resources. It also supports an intuitive paging cursor system, making it easy to manage large data sets and streamline the back-filling or monitoring process for contract events.
Key Benefits:
- Efficient Retrieval: Skip the hassle of manual block iteration and get only the logs you need.
- Historical Data Back-filling: Ideal for fetching past events (historical data) from a contract for data analysis, audits, or syncing with off-chain databases.
- Real-time Polling: If needed, this API can also be used for polling, efficiently fetching logs as they are emitted without redundant processing.
- Easy to Use: With paging support, it handles large amounts of data seamlessly, allowing for smooth navigation and retrieval without getting bogged down by complex query structures.
Use Cases:
- Blockchain Analytics: Extract detailed event data from smart contracts to power on-chain analytics, insights, and dashboards.
- Historical Data Backfill: Use it to retrieve historical logs for reconstructing transaction histories or syncing on-chain data with external systems.
- DeFi & NFT Platforms: Easily track important contract events such as token transfers, swaps, or minting without worrying about unnecessary overhead.
- Auditing & Compliance: Auditors can use this API to efficiently gather event logs from contracts, helping them review on-chain activity for compliance and transparency.
- A real-world example of this API's value is a game studio that collects logs from its smart contracts every morning. By using the "Get all logs from a contract" API, the studio retrieves all the logs generated by their contracts from the previous day. These logs are essential for tracking in-game transactions, user activity, and event triggers such as purchases, trades, or other interactions. The studio uses this data for daily analytics to calculate and distribute rewards to their players, ensuring fair play and transparency. Without this API, the studio would need to manually poll each block and filter through irrelevant data, which is both time-consuming and inefficient.
- For smart contract engineers, accessing contract logs during development is crucial to track events, debug issues, and validate contract behavior. The "Get all logs from a contract" API provides an easy-to-use tool for developers to retrieve all relevant logs from their contracts. Instead of manually querying each block and filtering through unnecessary data, this API simplify the process by returning only the logs that matter, making it faster and more efficient. Engineers can quickly inspect events emitted by their contracts, ensuring that everything is working as expected, without needing to navigate complex query structures or waste time sifting through irrelevant data.
The API also supports order
in query parameter to help client navigate their traversal, either from old to new or new to old data.
The API returns the up-to-date data, which means the chain head in some cases, users should be aware of reorgs data changes, and consider to handle reorgs.
While this API supports all event names (in hashes), we also provide a specialized API
for getting only transfer
event only with decoded data, returned data are making sure to be finalized.
Get all logs of a contract
To get logs list, use this get logs by contract address API
It requires one parameter (in path):
contractAddress
: contract address
Optional parameters (in query):
limit
: how many items can be return in a single response, maximum 200cursor
: the current pointer of the result set, to iterate to the next part of the results, it's returned by the previous call (nextCursor
field), you get it and pass to the next call, presentnextCursor
means there will be more results to scroll, emptynextCursor
means it reaches to the end of resultsorder
: specify the order of result set. For most APIs,order
might not be supported but the default valuedesc
, otherwise you can choose betweendesc
andasc
. Desc ordering usually refers to show latest elements over older elements
Example of 0xa8754b9fa15fc18bb59458815510e40a12cd2014 SLP contract address:
curl --location 'https://api-gateway.skymavis.com/skynet/ronin/web3/v2/logs/contracts/0xa8754b9fa15fc18bb59458815510e40a12cd2014?limit=2' \
--header 'Accept: application/json' \
--header 'X-API-KEY: <YOUR_API_KEY>'
Response:
{
"result": {
"items": [
{
"address": "0xa8754b9fa15fc18bb59458815510e40a12cd2014",
"topics": [
"0x7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f",
"0x0000000000000000000000000000000000000000000000000000000000000000",
"0x000000000000000000000000ed4a9f48a62fb6fdcfb45bb00c9f61d1a436e58c"
],
"data": "0x",
"blockNumber": 2670091,
"transactionHash": "0x6873a6527df184e40978e83be9f7769e4213e50029fb94104c6b97606377991a",
"transactionIndex": 0,
"blockHash": "0x38e05fc23d1950047a05bfdefe8d394b21fb4e18e27a51322cdae84bfb208cac",
"logIndex": 0,
"removed": false
},
{
"address": "0xa8754b9fa15fc18bb59458815510e40a12cd2014",
"topics": [
"0x6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f6",
"0x000000000000000000000000e35d62ebe18413d96ca2a2f7cf215bb21a406b4b"
],
"data": "0x",
"blockNumber": 2670094,
"transactionHash": "0xebf38ac26ff9c382d984bc8aabdc1d24d07142220c663d3c2b78ea27707f471b",
"transactionIndex": 0,
"blockHash": "0x27ba1bae71f18417bcd735a657a68ded81f1184fac2abdb9cb8eaa7b6bc5ff71",
"logIndex": 0,
"removed": false
}
],
"paging": {
"nextCursor": "MjY3MDA5NDow"
}
}
}
Get all logs of a contract and a log topic
If you are interested only in a certain kind of log event, use this get logs by contract address and log topic API
It requires one parameter (in path):
contractAddress
: contract addresstopic
: contract address
Optional parameters (in query):
limit
: how many items can be return in a single response, maximum 200cursor
: the current pointer of the result set, to iterate to the next part of the results, it's returned by the previous call (nextCursor
field), you get it and pass to the next call, presentnextCursor
means there will be more results to scroll, emptynextCursor
means it reaches to the end of resultsorder
: specify the order of result set. For most APIs,order
might not be supported but the default valuedesc
, otherwise you can choose betweendesc
andasc
. Desc ordering usually refers to show latest elements over older elements
Example of 0xa8754b9fa15fc18bb59458815510e40a12cd2014 SLP contract address, and 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef topic (transfer event):
curl --location 'https://api-gateway.skymavis.com/skynet/ronin/web3/v2/logs/contracts/0xa8754b9fa15fc18bb59458815510e40a12cd2014/topics/0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef?order=asc&limit=2' \
--header 'Accept: application/json' \
--header 'X-API-KEY: <YOUR_API_KEY>'
Response:
{
"result": {
"items": [
{
"address": "0xa8754b9fa15fc18bb59458815510e40a12cd2014",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x0000000000000000000000000000000000000000000000000000000000000000",
"0x000000000000000000000000e35d62ebe18413d96ca2a2f7cf215bb21a406b4b"
],
"data": "0x000000000000000000000000000000000000000000000000000000000000000a",
"blockNumber": 2674405,
"transactionHash": "0x05fa293ea8f4656fce26cb81fb16c6863c6a2d45e5a03595046b8c2d7d6a689a",
"transactionIndex": 0,
"blockHash": "0xffcc62db9e3557b4c3405cdab5103a42f847ece33fe372d9c0678d6da7a30200",
"logIndex": 0,
"removed": false
},
{
"address": "0xa8754b9fa15fc18bb59458815510e40a12cd2014",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x000000000000000000000000e35d62ebe18413d96ca2a2f7cf215bb21a406b4b",
"0x000000000000000000000000d82e037097ca7c77fc3aa1033547585cc6eb5bfe"
],
"data": "0x000000000000000000000000000000000000000000000000000000000000000a",
"blockNumber": 2674405,
"transactionHash": "0x05fa293ea8f4656fce26cb81fb16c6863c6a2d45e5a03595046b8c2d7d6a689a",
"transactionIndex": 0,
"blockHash": "0xffcc62db9e3557b4c3405cdab5103a42f847ece33fe372d9c0678d6da7a30200",
"logIndex": 1,
"removed": false
}
],
"paging": {
"nextCursor": "MjY3NDQwNTox"
}
}
}
The response returned from the API may vary in the future as the state of NFTs/Ownership/Collections can change.