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
Install Foundry binary
curl -L https://foundry.paradigm.xyz | bash
If you have installed foundry script or want to check
Next, if you take a look at the src/ folder, you will see Counter.sol :
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract Counter {
uint256 public number;
function setNumber(uint256 newNumber) public {
number = newNumber;
}
function increment() public {
number++;
}
}
To compile it, simply run forge compile
[⠊] Compiling...
[⠆] Compiling 27 files with Solc 0.8.23
[⠰] Solc 0.8.23 finished in 1.22s
Deploying your contract
In folder scripts/ there is file Counter.s.sol :
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Script, console} from "forge-std/Script.sol";
import {Counter} from "../src/Counter.sol";
contract CounterScript is Script {
Counter public counter;
function setUp() public {}
function run() public {
vm.startBroadcast();
counter = new Counter();
vm.stopBroadcast();
}
}
counter = new Counter(); this line only is how create or deploy new contractto deploy run