This is a modern Solidity template for Ethereum smart contracts. It combines two extremely powerful frameworks:
- Foundry - for Unit tests written in Solidity (contracts/test/).
- Hardhat - for Integration tests written in Typescript (integration/).
These frameworks also offer some advanced tools for contract debugging, deployment, gas measurements, etc.
integration/ - "Integration tests with Hardhat"
|- git-consensus.test.ts
scripts/
|- console.ts - "Terminal CLI functions"
|- deploy.ts - "Contract deployment functions"
contracts/
|- interfaces/
|--- IGitConsensus.sol - "Git Consensus Interface"
|- lib/ - "Utility functions"
|--- Utils.sol
|- test/ - "Unit tests with Foundry"
|--- GitConsensus.t.sol
|- GitConsensus.sol - "Git Consensus Implementation"`
.env - "Real environment vars"
.env.example - "Example environment vars"
.eslintignore - "Ignore list for eslint"
.eslintrc - "Configure eslint"
.gitignore - "Ignore list for Git"
.solcover.js - "Configure coverage"
.solhint.json - "Configure Solidity linter"
.prettierignore - "Ignore list for Prettier"
.prettierrc.json - "Configure Prettier"
deployments.json - "List of contract addresses on each network"
foundry.toml - "Configure Foundry"
hardhat.config.ts - "Configure Hardhat"
LICENSE - "Software license"
package.json - "Node dependencies"
slither.config.json - "Configure Slither"
tsconfig.json - "Configure Typescript"
--- (not an extensive list of all files) ---
git clone https://github.com/git-consensus/contracts.git && cd contracts
npm install -g npm
cp .env.example .env
Fill in at least your MNEMONIC
.
npm i
If this fails, you may need to run some additional steps for nodegit:
-
Mac:
npm config set python $(which python2)
-
Linux:
apt-get install -y python2 python3 libkrb5-dev gcc openssl libssh2-1-dev libcurl4-openssl-dev g++ make npm config set python $(whereis python2)
-
Windows:
Open powershell with administrator privileges and run this command:
npm install -g --production windows-build-tools
curl -L https://foundry.paradigm.xyz | bash
Then, in a new terminal session or after reloading your PATH
, run this to get
the latest forge
and cast
binaries:
foundryup
If you've made it this far, the repository setup is now complete! 🎉
Finished Setup?
forge test
This will run everything in contracts/test/, which utilizes Forge to test contract code.
npm run test
This will run everything in integration/, which utilizes Hardhat to tests for full usage scenarios.
Create a .env file matching the variables seen in .env.example.
Getting fully prepared may involve getting a INFURA_API_KEY
by signing up, and getting some test ETH on your target network via a facet.
Then run:
npm run deploy -- --network goerli
Ensure ../docs
path exists for the docs repo. If it isn't:
git clone https://github.com/git-consensus/docs.git ../docs
Now you can automatically convert NatSpec comments in contracts to docs with:
npm run doc
Advanced ways to use foundryup
, and other documentation, can be found in the foundryup package.
Foundry is a blazing fast, portable and modular toolkit for Ethereum application development. It consists of:
- Forge: Library for Unit / Fuzz testing written in Solidity (see contracts/test/).
- Cast: Library for interacting with a live Ethereum JSON-RPC compatible node, or for parsing data. A swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
Need help getting started with Foundry? Read the 📖 Foundry Book.
Hardhat is an Ethereum development environment for professionals. We use the Hardhat Network for Integration testing which written in Typescript. It uses Ethers.js and Mocha/Chai. See integration/ for how it's used in Git Consensus.
On Hardhat's website you will find:
- Solidity Visual Developer
- Solidity Language & Themes (only)
- Solidity (by Hardhat authors)
- Solidity (by Juan Blanco)
- ETHover
- Prettier
- Template String Converter
- Mocha Test Explorer
- Add Solidity comments in the natspec format.
- Always
npm run pretty
your before committing. - Lowercase commit message (for consistency).
- Embed your Ethereum address in your commit message on this repository.
- Integration testing with Mocha/Chai asserts:
expect(actual).to.equal(expected)
- Use Template Literals where possible.
- Use same consistent pattern for import ordering.
In general, please do your best to always keep this repository beautiful! ❤️