This is a boilerplate for deploying a contract to any network, if some networks are missing please feel free to add them. if read carefully this is very easy to use and extremely useful can save tons of time.
- clone this repo
npm install --save-dev
- rename
.env.example
to.env
- fill all the fields in
.env
- add your networks to
hardhat.config.js
as follows
mainnet : {
url : `${process.env.MAINNET_PROVIDER_URL}`,
accounts: [
process.env.DEPLOYER_PRIVATE_KEY || privateKeys[1],
process.env.GOVERNOR_PRIVATE_KEY || privateKeys[1],
],
chainId: 1,
},
- Add your Scan API KEY for the verification
- the naming is important so you may check how to name your etherscan networks here https://hardhat.org/plugins/nomiclabs-hardhat-etherscan.html
etherscan: {
apiKey: {
polygonMumbai: process.env.POLYGONSCAN_API_KEY,
},
},
deploy.js
andtx.js
include deployer functions- To deploy use the following function :
await deployWithConfirmation('UserRegistry');
//OR if you wanna reuse the address after deploying
const dUserRegistry = deployWithConfirmation('UserRegistry');
// you might call then dUserRegistry.address
- All your contracts will go inside
/contracts
, you may open subfolders such as/contracts/core
, you dont need to add the complete PATH to the deployment function, a name is sufficient - You can call your previously defined name accounts as follows
const {deployerAddr, governorAddr} = await getNamedAccounts();
- To read the latest deployed contract which is stored in
/deployments
use :
//by using this function you are giving the contract an ABI and address which are already stored
const cUserRegistry = await ethers.getContract('UserRegistry');
- Another way to read a contract :
//will look for ABI of UserRegistry in /artifacts and use the address to read on-chain
const cUserRegistry = await ethers.getContractAt('UserRegistry','0x30f38906eFa003244bE583e49E362f57130FA056');
- To perform transaction that is needed to be
DONE
to continue with the deployment script
await withConfirmation(
cUserRegistry.modifyUser('hola', 'emerson',1)
)
It's possible to Fork the current status of the mainnet into a local node and run tests on it, this is very useful for projects that need to interact with existing contracts, also useful for testing deployed contracts after a vulnerability has been found.
- Archive node provider, preferably Alchemy ( add them to your
.env
) - Currently Supporting Mainnet, Polygon and BSC, feel free to add more :)
Allows you to fund accounts that you added to your .env
, using the tokens that are declared there as well.
There is a SANITY CHECK :
- check all the tokens that you need are declared in
addresses.js
- make sure there is a funder for each token in
addresses.js
- make sure the decimals of the token are addded to
constants.js
- if the call fails, check if the funders have enough funds and GAS (i.e. ETH).
yarn deploy --network {network name as in config.js}
yarn verify --network {network name as in config.js} {contract address}
yarn node:{network}
yarn deploy:{network}
yarn fund:{network} --amount {AMOUNT} --localaccounts {number of local accounts to fund}