Ethereum Smart Contract Template
This development quick start template is heavily inspired by Georgios's template. Over time it was migrated to use foundry since dapptools was deprecated.
It requires Foundry installed to run. You can find instructions here Foundry installation.
Installation
GitHub template
It's easiest to start a new project by clicking the "Use this template".
Manual installation
If you want to create your project manually, clone the template in a new folder and cd
into it.
Clone the template, install dependencies and make sure tests work:
mkdir cool-dapp
cd cool-dapp
forge init --template https://github.com/cleanunicorn/ethereum-smartcontract-template
# Install the project's dependencies (libs and yarn packages)
make
# Run tests
make test
Features
For Foundry specific features, refer to:
This template comes with an additional set of features explained below.
Solidity libraries
Included libraries in lib
:
- ds-test - Test framework for DappTools
- openzeppelin-contracts - OpenZeppelin contracts library
- mockprovider - Mocking library
GitHub Actions
The template already comes with GitHub actions configured, which means that the project will be tested on every push
and pull request
.
Check the project's actions for an example.
Actions are defined in .github/workflows/ci.yml.
GitHub templates
The template comes with a list of templates:
Commands
make setup
- initialize libraries and yarn packagesmake build
- build your projectmake xclean
- remove compiled filesmake lint
- lint filesmake test
- run testsmake test-gasreport
- run tests and show gas reportmake watch
- watch files and re-run tests
Testing
Normally you would run your tests on the local evm engine.
$ make test
forge test --gas-report
[⠊] Compiling...
[⠑] Compiling 19 files with 0.8.13
Compiler run successful
Running 2 tests for OnlyAuthorizedTest.json:OnlyAuthorizedTest
[PASS] testCanChangeOwner() (gas: 11542)
[PASS] testOtherUsersCannotChangeOwner() (gas: 156817)
╭─────────────────┬─────────────────┬──────┬────────┬──────┬─────────╮
│ Caller contract ┆ ┆ ┆ ┆ ┆ │
╞═════════════════╪═════════════════╪══════╪════════╪══════╪═════════╡
│ Deployment Cost ┆ Deployment Size ┆ ┆ ┆ ┆ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ 114159 ┆ 602 ┆ ┆ ┆ ┆ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ Function Name ┆ min ┆ avg ┆ median ┆ max ┆ # calls │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ externalCall ┆ 6419 ┆ 6419 ┆ 6419 ┆ 6419 ┆ 1 │
╰─────────────────┴─────────────────┴──────┴────────┴──────┴─────────╯
╭─────────────────────────┬─────────────────┬──────┬────────┬──────┬─────────╮
│ OnlyAuthorized contract ┆ ┆ ┆ ┆ ┆ │
╞═════════════════════════╪═════════════════╪══════╪════════╪══════╪═════════╡
│ Deployment Cost ┆ Deployment Size ┆ ┆ ┆ ┆ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ 133694 ┆ 607 ┆ ┆ ┆ ┆ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ Function Name ┆ min ┆ avg ┆ median ┆ max ┆ # calls │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ changeOwner ┆ 2504 ┆ 3980 ┆ 3980 ┆ 5457 ┆ 2 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ owner ┆ 335 ┆ 335 ┆ 335 ┆ 335 ┆ 1 │
╰─────────────────────────┴─────────────────┴──────┴────────┴──────┴─────────╯
╭─────────────────────────────┬─────────────────┬────────┬────────┬────────┬─────────╮
│ OnlyAuthorizedTest contract ┆ ┆ ┆ ┆ ┆ │
╞═════════════════════════════╪═════════════════╪════════╪════════╪════════╪═════════╡
│ Deployment Cost ┆ Deployment Size ┆ ┆ ┆ ┆ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ 741677 ┆ 3639 ┆ ┆ ┆ ┆ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ Function Name ┆ min ┆ avg ┆ median ┆ max ┆ # calls │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ setUp ┆ 171174 ┆ 171174 ┆ 171174 ┆ 171174 ┆ 2 │
╰─────────────────────────────┴─────────────────┴────────┴────────┴────────┴─────────╯
Changes
Listed in the CHANGELOG.md file which follows the https://keepachangelog.com/en/1.0.0/ format.
Testing forked chain
Work in progress...