Troubleshoot issues with your protocol during development and testing.
Protocol development can often involve frustrating errors that consist of inscrutable bytecode. Function calls staged to a Safe might not be legible. A dreaded 0x
error may be returned from a contract with no reason for the revert to be found.
Cannon can leverage data from packages to decode bytecode, generate human-readable stack traces, and send transactions to protocols.
To use the decode
, trace
, and interact
commands, start by installing/upgrading Cannon:
npm i -g @usecannon/cli
You may encounter a hex string related to a protocol, but can’t tell what it is. Centralized services such as ABI Tools or the Ethereum Signature Database may be able to help, but won’t be useful during protocol development or if the relevant ABI hasn’t been uploaded there.
You can pass hex data to Cannon’s decode
command, along with the package name and a relevant chain ID, to get a human-readable version of function calls, function output, event data, and error data.
For example, the following command decodes error data:
cannon decode synthetix-omnibus --chain-id 84531 --preset competition 0xb87daa32000000000000000000000000000000000000000000000000000000006502188b00000000000000000000000000000000000000000000000000000000650218190000000000000000000000000000000000000000000000000000000065021855
If you’d like to better understand the execution of a transaction—whether or not it resulted in an error—you can use Cannon’s trace
command. This command accepts a transaction hash from a remote network or hex-encoded transaction data (as you might find in a gas estimation error).
The command includes some options that allow you to simulate how a transaction (or transaction data) would execute under different circumstances: --block-number
, --to
, --from
, and --value
. Note that you must connect to an archive node (using the --provider-url
option) to successfully simulate a call on a historical block.
For example, the following command provides a full stack trace for retrieving the debt associated with a pool’s vault in Synthetix V3:
cannon trace --chain-id 10 synthetix-omnibus 0x2fb8ff2400000000000000000000000000000000000000000000000000000000000000010000000000000000000000008700daec35af8ff88c16bdf0418774cb3d7599b4 --to 0xffffffaEff0B96Ea8e4f94b2253f31abdD875847 --provider-url https://optimism.publicnode.com
Similar to the interact tab in the package explorer, the CLI allows you to call view functions and send transactions to protocols in the command-line interface.
For example, you can use the interact tool to call functions on Synthetix V3:
cannon interact synthetix --chain-id 1 --provider-url https://ethereum.publicnode.com
If you’d like to send transactions, you can use Frame or include a private key using either an environment variable CANNON_PRIVATE_KEY
or the --private-key
option.
For more information on the command-line interact command, see the CLI section of the documentation.