Troubleshooting
Debug transaction failures
EVM execution environments often provide limited ways to figure how exactly a transaction failed to execute. Due to the complexity of a DEX aggregator involving both on-chain and off-chain components it is often useful to have an reliable way to trace the transaction.
Foundry toolkit provides a useful command for to solve this problem:
cast run 0x8e14deeb46f1757b21a0fcb4badb0a5296c7a2d20ec3963732214ed74cb3c03e --rpc-url https://bartio.rpc.berachain.com
This will show a breakdown of the transaction execution and the different contract interactions.
Assuming the transaction failed, you it is likely to throw an error signature like 0x71c4efed
(SlippageExceeded
). You can look up the full list of errors in our OBRouter Errors.
Alternatively if the error is not found on the table, foundry also provides cast-4byte which can decode the error if it is already present in their lookup table like so:
cast 4byte 0x71c4efed
In case you've found a transaction that is reverting in unexpected ways, feel free to reach out to us on discord.
OutOfGas transactions
Recently we've realised that bArtio's gas estimation on transactions can be inaccurate at times. And leading to failed transactions due to insufficient gas provided if you look up the transaction on block explorer or using the debug transaction failures approach.
At the time of writing, by default, viem/wagmi will always try to estimate gas from the RPC if the no gas limit is set to the transaction. And this gas estimation often leads to incorrect estimates that lead to transactions failing OutOfGas
.
[OutOfGas] EvmError: OutOfGas
One solution that we've incorporated in our frontend and we recommend other integrators to do as well is to manually estimate gas of the transaction from the RPC and then post the swap transaction along with an extra buffer added on top of the estimated gas value returned by the RPC. This has been a successful measure in dealing with this issue.
We recommend setting an extra buffer between 10%-20% of gas on top of the returned value.
Below is an example of how this is achieved using viem:
const gas = await publicClient.estimateGas({
account: tx.from as Address,
to: tx.to as Address,
data: tx.data as `0x${string}`,
value: tx.value ? BigInt(tx.value) : 0n,
});
// Add 10% gas buffer
const gasWithBuffer = (gas * 11) / 10;
await client.sendTransaction({
account: tx.from as Address,
to: tx.to as Address,
data: tx.data as `0x${string}`,
value: tx.value ? BigInt(tx.value) : 0n,
gas: gasWithBuffer,
});