Decode events and calls for historical and real-time data

Background

An ABI (Application Binary Interface) decoder is a tool that converts the data of events or function calls from the blockchain into human-readable information. It utilizes the ABI definition of a smart contract to map the raw hexadecimal data in events or function calls to the ABI's specified data types and values.

For example, instead of a hexadecimal-character string representing the event signature "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", the ABI decoder translates the string into its corresponding event name "Transfer".

Additionally, you can observe the indexed parameters of the event. Since it is a transfer event for ERC-20 tokens, "topic 1" stands for "from", and "topic 2" stands for "to". Notice that the transfer event below has more than two parameters, but it is common to refer primarily to indexed parameters.

Transfer (index_topic_1 address from, index_topic_2 address to, uint256 value)

Use cases

An ABI decoder can assist developers and users in understanding the details of a blockchain transaction or event as it provides a more user-friendly representation of the data. It can also help debug issues with smart contracts, as it becomes easier to identify any unexpected values or errors in the data.

For example, imagine a smart contract with an event triggered whenever a user transfers funds. In that case, the raw data for the event in the blockchain might look like a hexadecimal-character string, difficult for a human to interpret. Using the contract's ABI definition, the ABI decoder can decode this data and display the actual values of the event parameters, such as the sender's address, the recipient's address, and the number of funds transferred.

Set up an ABI

Setting up an ABI on Tsunami API is a simple process that can be accomplished in a few steps:

  1. Open your Harbour account.

  1. Navigate to the ABI decoder section.

  1. Click on the "+ Upload new ABI" button.

  1. Upload the ABI of the contract you wish to monitor.

  1. Select the "Events" and/or "Calls" to be decoded and save your ABI decoder.

Getting the ABI of a particular contract

To monitor a third-party contract, use Etherscan or a similar blockchain explorer service. Search for the contract address you want to keep track of. In this case, the example address corresponds to Uniswap's token contract.

Once on the contract's page, look for the 'Contract' tab or a similar section that provides contract-related information.

In the "Contract" tab, find the contract's code. Look for a section that mentions the contract's ABI and copy it from the provided location. The ABI is usually a JSON object that describes the contract's functions, events, and variables.

📘

Please note that the provided instructions may vary slightly depending on the specific blockchain explorer service you are using.

ABI Decoder X Real-Time Filters

The ABI decoder is seamlessly integrated into our real-time filters solution, making monitoring events and calls within your contract effortless. By specifying the contract you wish to track and uploading its ABI, you can access a comprehensive list of available events and calls, along with their decoded names and parameters. For detailed instructions on setting up an ABI decoder in real-time filters, refer to the guide here.

ABI Decoder X 'Get Decoded Events' Endpoint

The ABI decoder can decode historical events on the fly with the Get Decoded Events endpoint. Its functionality operates similarly to the Get Events endpoint, except that it provides the actual name of the event along with its indexed parameters. Remember to include the ABI in the request body

ABI Decoder X 'Get Decoded Calls' Endpoint

The ABI decoder can decode historical calls on the go with the Get Decoded Calls endpoint. It functions similarly to the Get Calls endpoint but allows you to retrieve the actual call name and its indexed parameters. Make sure to include the ABI in the request body.