sumit03guha / smart-contracts-development-boilerplate

A boilerplate repository for smart contracts development, based on hardhat and includes foundry fuzzing.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Smart Contracts Development Boilerplate

This smart-contracts-development-boilerplate is mostly based on hardhat and includes foundry fuzz-testing feature.

Prerequisites

  • Install foundry for fuzzing the smart contracts. Go through the installation instructions to install foundry.
  • Configure the foundry.toml as per your requirements. Refer to the foundry config reference for more details.
  • Install truffle : npm i -g truffle
  • The latest version of truffle has issues with installation on Windows.
  • To resolve the errors, go to this page, download Microsoft Visual Studio 2022 and then install the Visual Studio Installer.
  • Select Desktop Development with C++ and uncheck all the optional installation options.
  • Once it is done, the truffle can be installed with npm i -g truffle

Instructions and commands

  • Install the boilerplate project dependencies.
    Do a check for the latest npm package versions.
    This will update the versions inside the package.json.

    npx npm-check-updates -u
    git submodule update --init --recursive
    yarn

    This will install the packages mentioned inside the package.json file.

  • Compile the smart contracts.

    yarn clean-compile
  • Check for linting and formatting errors in the code. This will display all the code errors and warnings in the terminal.

    yarn check
  • Generate the typechain types for the smart contracts. This will create a typechain-types folder comprising all the typechain types, in the root directory of the project.

    yarn typechain
  • Compute the size of the smart contracts. This will display the size of the smart contracts in the terminal.

    yarn size
  • Run the test scripts. This uses the hardhat network configured in the hardhat.config.ts file to run the tests.

    yarn test
  • To run the tests on your localhost node for debugging purposes, you can run the following commands.
    Instantiate the hardhat local node.

    yarn localnode
  • Split the terminal running the hardhat node, or, open another terminal and run the project test scripts using the local node.

    yarn test:local
  • Run the foundry test cases, written in solidity, which should be present inside the test/foundry folder.

    yarn test:forge
  • Generate the code coverage report.
    After generating the report, you can open the coverage/index.html file to see the results.

    yarn coverage
  • Generate the documentation for the smart contracts. This will create a docs folder comprising all the documentation related to the smart contracts, in the root directory of the project.

    yarn doc
  • Instantiate the truffle dashboard.
    This lets you deploy the contracts without the need of pasting the private key anywhere in the project.

    truffle dashboard
  • The browser will open up and then you have to connect with the MetaMask extension. Select the preferred network and the account to deploy the smart contract.

  • Deploy the hardhat project smart contracts using your preferred network or the truffle dashboard, by specifying the NETWORK. If you are using any network other than truffle or localhost, then the private key of the account from which the smart contract is to be deployed, should be specified in the .env file.

    yarn deploy {NETWORK}
  • If truffle has been specified as the NETWORK, then switch to the browser and sign the deployment transaction from the MetaMask extension.

  • After the succesful deployment of the smart contracts, a build/deploy.json file will be generated comprising the deployed addresse and the ABI of the smart contracts.

  • Verify the smart contract using the NETWORK on which it was deployed and the smart contract address, alongwith the constructor arguments by modifiying the verify.ts file, and entering the network name in the CLI after running the following command.

    yarn verify {NETWORK}

A typical top-level directory layout

.
├── build                 # deployed addresses and the ABI of the smart contract (scripts/deploy.ts)
  └── artifacts           # hardhat deployment information [hardhat default]
  └── cache               # hardhat deployment information [hardhat default]
  └── deployments         # address and ABI of the smart contract [modified after hardhat default]
  └── foundry             # cache and output generated by foundry [gitignored]
├── contracts             # smart contracts solidity files
├── coverage              # coverage report (index.html) [gitignored]
├── docs                  # smart contracts documentation
├── lib                   # git submodule for foundry testing
├── node_modules          # npm/yarn dependency files [gitignored]
├── scripts               # deployment scripts (deploy.ts) and other tasks [modified after hardhat default]
├── test                  # test scripts [modified after hardhat default]
  └── foundry             # test scripts for foundry and fuzzing
├── typechain-types       # typechain types, generated after compilation [gitignored]
├── .env                  # API keys of block explorers for smart contract verification [should be gitignored]
├── .env.example          # format for structuring the .env file
├── .prettierrc           # prettier formatting configuration
├── .solhint.json         # solhint configuration
├── .solhintignore        # solhint ignore configuration
├── .yarnrc.yml           # https://yarnpkg.com/getting-started/migration#if-required-enable-the-node-modules-plugin
├── coverage.json         # gitignored
├── foundry.toml          # foundry configuration https://book.getfoundry.sh/static/config.default.toml
├── hardhat-config.ts     # hardhat configuration [modified after hardhat default]
├── package.json          # project details and dependencies
├── README.md             # project details and instructions
├── remappings.txt        # foundry remappings https://book.getfoundry.sh/reference/forge/forge-remappings
├── tsconfig.json         # typescript configuration [hardhat default]
├── yarn.lock             # yarn dependencies
├── .gitmodules
└── .gitignore

Notes

  • All the files and folders that have been [modified after hardhat default], as mentioned in the above directory layout, consists of well-commented codes in the respective places, regarding the modifications.

About

A boilerplate repository for smart contracts development, based on hardhat and includes foundry fuzzing.


Languages

Language:TypeScript 87.0%Language:Solidity 13.0%