Time to read: 1 min
Smart Contract
Folder Structureβ
Letβs view the file structure for a default foundry project:
$ cd hello_foundry
$ tree . -d -L 1
.
βββ lib
βββ script
βββ src
βββ test
4 directories
Demo smart contractβ
In the src
folder, you will find a simple smart contract called counter.sol
. Which contains a simple counter contract.
// 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++;
}
}
Compile the Contractβ
To build the contract, run the following command in the project's root directory.
forge build
This will compile your smart contracts and generate out
directory:
forge build
[β ] Compiling...
[β ] Compiling 36 files with Solc 0.8.24
[β ] Solc 0.8.24 finished in 1.56s
Compiler run successful!