For the complete documentation index, see llms.txt. This page is also available as Markdown.

Foundry Integration

Build a Foundry project from scratch, configure it for Cronos EVM, and deploy a sample contract with forge script.

Foundry is a Solidity-native toolchain: tests, deploy scripts and fixtures are all written in Solidity, and there is no Node.js dependency.

Prerequisites

  • A wallet private key: With a small amount of CRO to pay for gas fees. (For testnet TCRO, use the faucet at https://faucet.cronos.com/.)

  • An RPC endpoint: See details here.

  • A Cronos Explorer API key, see how to obtain it here.

Step 1. Install Foundry

Run the following in your terminal:

curl -L https://foundry.paradigm.xyz | bash && foundryup

This installs forge, cast, anvil and chisel.

Verify the installation with:

forge --version

Step 2. Create and initialize the project

forge init my-cronos-project
cd my-cronos-project

Foundry creates the following structure:

my-cronos-project/
├── src/          # Your contracts
├── test/         # Tests
├── script/       # Deployment scripts
└── foundry.toml  # Project configuration

Step 3. Write your contract

forge init creates a sample contract Counter.sol at src/. You can remove it and add your contracts to src/.

Step 3.1. Install Dependencies

For example, to add OpenZeppelin as a dependency:

Then add the remapping to foundry.toml:

Step 4. Configure .env

Create a .env file in the project root:

Then load it before running any scripts:

Check how to get a Cronos Explorer API key here.

Step 5. Configure Cronos

Set the compiler, both RPC aliases and both verification endpoints in foundry.toml , example config:

Foundry has no gasPrice config field, instead it reads the gas price from the node via eth_gasPrice, which is correct on Cronos. If a transaction stalls, override it explicitly with --gas-price 10100000000000 (10,100 gwei) — check the current level at explorer.cronos.com/charts.

Step 6. Compile

Step 7. Test

forge init creates a sample test for Counter.sol at test/. To run it:

Step 8. Deploy

Foundry deploys with Solidity scripts, forge init creates a sample script at src/. To run it:

--rpc-url cronos_testnet refers to the alias defined in [rpc_endpoints]. Swap it for cronos_mainnet to deploy to mainnet. Drop --broadcast to simulate without sending anything.

Step 9. Verify

Run forge verify-contract after deployment:

For contracts that take parameters in contructor, add --constructor-args and cast abi-encode. For example, the verification command for an ERC20 token that takes name and symbol as constructor parameters will look like:

Last updated

Was this helpful?