This is my first project and it demonstrates a basic Hardhat use case. It comes with a sample contract SimpleStorage.sol
, a test for that contract test-deploy.ts
, a custom task to see block numbers in network tasks/block-number.ts
, and a script that deploys that contract scripts/deploy.ts
.
git clone https://github.com/chaosrei/hardhat-simple-storage-ts.git
cd hardhat-simple-storage-ts
yarn
yarn typechain
git checkout typescript
Deploy:
yarn hardhat run scripts/deploy.ts
Test:
yarn hardhat test
Test Coverage:
yarn hardhat coverage
- Setup environment variabltes
Set your SEPOLIA_RPC_URL
and PRIVATE_KEY
as environment variables. You can add them to a .env
file.
PRIVATE_KEY
: The private key of your account.SEPOLIA_RPC_URL
: This is url of the sepolia testnet node you're working with. You can get setup with one for free from AlchemyETHERSCAN_API_KEY
: This is API from etherscan.ioCOINMARKETCAP_API_KEY
This is API from coinmarketcap.com. It helps us to see current token price (e.g. in USD)- To disable Gas Reporter change
enabled
value tofalse
inhardhat.config.ts
:
- To disable Gas Reporter change
gasReporter: {
enabled: false,
...
}
- Get testnet ETH
Head over to sepoliafaucet.com and get some tesnet ETH.
- Deploy
yarn hardhat run scripts/deploy.ts --network sepolia
You can estimate how much gas things cost by running:
yarn hardhat test
And you'll see and output file called gas-report.txt
You can also change output filename in hardhat.config.ts
If you deploy to a testnet or mainnet, you can verify it if you get an API Key from Etherscan and set it as an environemnt variable named ETHERSCAN_API_KEY
. You can pop it into your .env
file.