Solidity Foundry Template
A template for solidity smart contract development with foundry.
Full article: https://olich.me//post/smart-contract-solidity-development-with-foundry
Getting Started
Click Use this template
on Github to create a new repository with this repo as the initial state.
Or run (also works for existing projects):
forge init --template https://github.com/soliditylabs/forge-erc20-template
git submodule update --init --recursive
forge install
Build
$ forge build
Test
$ forge test -vvv
# with gas report
$ forge test -gas-report
Format
$ forge fmt
Gas Snapshots
$ forge snapshot
Anvil
$ anvil
Deploy
# To load the variables in the .env file
$ source .env
# To deploy and verify our contract
$ forge script script/DeployMyToken.sol:DeployMyTokenScript --rpc-url $SEPOLIA_URL --broadcast --verify -vvvv
Cast
$ cast <subcommand>
Help
$ forge --help
$ anvil --help
$ cast --help
MyToken
Inherits: ERC20, Ownable
Implementation of the ERC20 standard with ownership features
Inherits from ERC20 and Ownable contracts from OpenZeppelin
Functions
constructor
Constructs the MyToken contract
Sets token name to "MyToken" and symbol to "MTK"
constructor(address initialOwner) ERC20("MyToken", "MTK") Ownable(initialOwner);
Parameters
Name | Type | Description |
---|---|---|
initialOwner | address | The address that will be granted initial ownership of the token |
mint
Allows the current owner to mint new tokens
Restricted to be callable only by the contract owner
function mint(address to, uint256 amount) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
to | address | The address that will receive the minted tokens |
amount | uint256 | The amount of tokens to mint |