blog debug Tests

Debugging your Ethereum transactions with Tenderly

Tenderly is a web app that has the mission to help developers and Ethereum companies in their building and maintaining dapps by providing real-time monitoring, alerting, and troubleshooting for Smart Contracts. In this example, we’ll see how Tenderly can be used to see what went wrong on a complex Ethereum transaction by analyzing it with their powerful debugger.

To use Tenderly, you’ll first need to create an account. Don’t worry their free starter plan is quite generous and will definitely be useful if you’re building on Ethereum.

To try the Tenderly debugger we’ll be looking into looking of a transaction of a DEX / Flash Loan arbitrage bot that operates on the Ethereum network. You can see the failed transactions here on Etherscan: 0xf24ef05bf86444eee80788b19f5cc7b92d1fe9091c69ec217659074b371721b6.

As you see the transaction failed and Etherscan does not give much information about why it failed and give a generic error message: “Warning! Error encountered during contract execution [Reverted]”. If you copy the transaction hash (0xf24ef05bf86444eee80788b19f5cc7b92d1fe9091c69ec217659074b371721b6) and paste it in the Tenderly search box at the top of the interface (when you’re logged in), we’ll be able to have much more details (click here if you’re logged into Tenderly). The transaction may take time to load as Tenderly replay the transaction at the block it was executed to get all the details needed to show you. As soon as it’s loaded you should see something like this:

As you can see, Tenderly directly display us the correct reason on why the transaction was reverted:

Join the newsletter

Get a weekly summary of what is happening in the Ethereum developer space for free

require(returnAmount >= minReturn, “OneSplit: actual return amount is less than minReturn”);

As we already studied about how 1inch works and about DEX arbitrage bots are working (part1, part2, part3). We know that when you call 1inch you need to provide the token you want to swap and the amount, the token you want to get nd the mnimum amount of return you want want to get and the distribution of DEXes that will be used by the swap. In this case we can conclude that the transaction failed because the amount of token returned by the swap is less than the amount of token the transaction specified.

Fortunately, the debugging tool enable us to go deeper to understand how the transaction went step by step before it failed. Let’s look at the first part of the transaction. It describes every calls to different smart contract that were made during the transaction:

The first part involves Dy/Dx protocol that can be used as a flash loan platform (see here). We can see that the flash loan has something to do with TetherToken (USDT). Then the second part involves a call to the swap function of 1inch dex aggregator:

If you overlay a function you’ll have the option to move to the debugger view of the selected state, we have this for the swap function:

You can see that once the transaction did the flash loan it first try to swap the tokens using 1inch. The from token is USDT, the toToken is wrapped Ether: WETH. The smart contract asks to swap 4234.575953 USDT to at least 19 Ether. As you can see Tenderly enable us to decode every prameter of internal calls even if the transaction failed. If you’re interacting with known contract the tool will directly decode the parameters for you otherwise you can dupload your own smart contracts to the platform.

If we scroll down enough until the place where the transaction was reverted at the end of the swap call:

If we go in the debugger view of this call we’ll be able to get details:

Thanks to the previous/next button you’ll be able to navigate each steps of the transaction and see that the return amount (one step before) was : 18.953135705079702716

So using Tenderly to debug the transaction we were able to see where and how the transaction failed in few minutes. This tool is really valuable for Ethereum developpers and users to understand why their transaction failed and can even be used to check how your succesful transactions bahaved step by step.

Tenderly is a tool we recommend to all developers that need to need to understand how their transactions went and how their smart contracts behave. As soon as your transactions are dealing with several DeFi protocols, it’s really hard to get a clear view of what is happening step by step. Moreover, Tenderly also offers other functionalities like transaction monitoring and analytics.

Leave a Reply