Deploying with Foundry

What is Foundry

Foundry is a smart contract development toolchain.Foundry manages your dependencies, compiles your project, runs tests, deploys, and lets you interact with the chain from the command-line and via Solidity scripts.For more information please visit: Foundry Book

Setting up the development environment

  1. Install Foundry binary

  • curl -L https://foundry.paradigm.xyz | bash
  1. If you have installed foundry script or want to check

  • forge --version

Project Config

In root project it has foundry.toml

Next edit file as below

## foundry.toml
[profile.default]
libs = ['lib']
out = 'out'
src = 'src'

optimizer = true
optimizer_runs = 200
solc_version = "0.8.13"

# See more config options https://github.com/foundry-rs/foundry/tree/master/config

[rpc_endpoints]
sixnet = "${SIXNET_RPC_URL}"
fivenet = "${FIVENET_RPC_URL}"

[etherscan]
fivenet = {key = "ANY STRING HERE", chain = 150, url="https://fivenet.evm.sixscan.io/api"}
sixnet = {key = "ANY STRING HERE", chain = 98, url="https://evm.sixscan.io/api"}

Next set up .env file. Foundry required .env

  1. Create .env file by

  1. Edit .env file as below

Compiling your contract

Next, if you take a look at the src/ folder, you will see Counter.sol :

To compile it, simply run forge compile

Deploying your contract

In folder scripts/ there is file Counter.s.sol :

counter = new Counter(); this line only is how create or deploy new contractto deploy run

  1. source .env to initialize our environment

  2. forge script script/Counter.s.sol:CounterScript --broadcast --optimize --rpc-url $FIVENET_RPC_URL --private-key $PRIVATE_KEY

Verify your contract

Output will similar to

Last updated