Foundry is a smart contract development toolchain that manages your dependencies, compiles your project, runs tests, deploys, and lets you interact with the chain from the CLI and via Solidity scripts.
To start a new project with Foundry, use forge init:
The src folder may already contain Counter.sol, a minimal Solidity contract.
Setup Foundry For ThunderCore
Edit foundry.toml to contain:
Compiling
Run the command forge build to build the project.
And test the build with "forge test".
Deploy to ThunderCore Network
Edit script/Counter.s.sol and add "new Counter()" at the end of run():
Use "forge script" to deploy your contract to ThunderCore:
Check the deployed contract in Explorer
Copy the address of your newly deployed contract from the output. Then go to the ThunderCore Blockchain Explorer, and paste the address in the Search by address field.
[profile.default]
evm_version = "london"
[rpc_endpoints]
thunder-mainnet = "https://mainnet-rpc.thundercore.com"
thunder-testnet = "https://testnet-rpc.thundercore.com"
# See more config options
# https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
$ forge build
$ forge test
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;
import {Script, console} from "forge-std/Script.sol";
import "../src/Counter.sol";
contract CounterScript is Script {
function setUp() public {}
function run() public {
vm.broadcast();
new Counter();
}
}
$ forge script --rpc-url thunder-testnet --broadcast --account deployer ./script/Counter.s.sol
[⠰] Compiling...
No files changed, compilation skipped
Enter keystore password:
Script ran successfully.
## Setting up 1 EVM.
==========================
Chain 18
Estimated gas price: 2360 gwei
Estimated total gas used for script: 138734
Estimated amount required: 0.32741224 ETH
==========================
##
Sending transactions [0 - 0].
⠁ [00:00:00] [#] 1/1 txes (0.0s)##
Waiting for receipts.
⠉ [00:00:12] [#] 1/1 receipts (0.0s)
##### 18
✅ [Success]Hash: 0xe459d759617b8f6054646cd0aa37e2c14db66a051747b0c32609b2e3c87c3d78
Contract Address: 0x8133D6f94ae2cB864540BF9a3c736dd6f6F2E426
Block: 1754750
Paid: 0.2454537 ETH (106719 gas * 2300 gwei)
==========================
ONCHAIN EXECUTION COMPLETE & SUCCESSFUL.
Total Paid: 0.2454537 ETH (106719 gas * avg 2300 gwei)
Transactions saved to: (...)/broadcast/Counter.s.sol/18/run-latest.json