Cannon
Beta

Search packages, etc.

Build with Cannon

Create and deploy a protocol that integrates with Cannon packages

Start by installing/upgrading the Cannon command-line interface:

npm i -g @usecannon/cli

Select your framework

Create a Cannonfile

Create a new Foundry project with forge init sample-project. This will generate the following contract:

Loading...

Create a cannonfile.toml in the root directory of the project with the following contents. If you plan to publish this package, you should customize the name. This will deploy the contract and set the number to 420:

Loading...

Now build the cannonfile for local development and testing:

cannon build

This compiled your code and created a local deployment of your nascent protocol. You can now run this package locally using the command-line tool. (Here, we add the --registry-priority local option to ensure we’re using the version of this package that you just built, regardless of what others have published.)

cannon sample-foundry-project --registry-priority local

Deploy Your Protocol

Deploying is just building on a remote network!

cannon build --network REPLACE_WITH_RPC_ENDPOINT --private-key REPLACE_WITH_KEY_THAT_HAS_GAS_TOKENS

Verify your project's contracts on Etherscan:

cannon verify sample-foundry-project --api-key REPLACE_WITH_ETHERSCAN_API_KEY --chain-id REPLACE_WITH_CHAIN_ID

Finally, publish your package on the Cannon registry:

cannon publish sample-foundry-project --private-key REPLACE_WITH_KEY_THAT_HAS_ETH_ON_MAINNET

Pull and Clone Packages

You can use packages in your Cannonfiles with the pull and clone operations.

pull  packages to reference the addresses in their deployment data. Find which networks each package has deployment data for on the registry explorer.

For example, the Synthetix Sandbox contains a Cannonfile that deploys the sample integration contract connected to the official deployment addresses. The relevant code looks like this:

Loading...

clone packages to deploy new instances of their protocol's contracts.

For example, the Synthetix Sandbox contains a Cannonfile that clones a new instance of Synthetix and sets up a custom development environment. This is a simplified version of the relevant code:

Loading...

Test Your Protocol

Install Cannon for Foundry:

forge install usecannon/cannon-std

Grant your Foundry project permission to read from the filesystem. Add the following line to your foundry.toml  file:

fs_permissions = [{ access = "read", path = "./"}]

Include the Cannon.sol library in your tests. Here's an example:

Loading...

Use the test command to run them. (Note that the --chain-id option can be used to run tests against a forked network.)

npx cannon test

Supported byOptimismandSafe