This is a simple smart contract made by using hardhat, which allows users to store a number and retrieve it. The users are mapped to the numbers respectively.
git clone https://github.com/0xSanyam/hardhat-simple-storage
Typescript is also included in scripts, tasks and test section.
yarn hardhat run scripts/deploy.js
yarn hardhat run scripts/deploy.ts
yarn hardhat test
yarn hardhat coverage
You can estimate how much gas things cost by running:
yarn hardhat test
You'll see an output file called gas-report.txt
If you'd like to run your own local hardhat network, you can run:
yarn hardhat node
And then in a different terminal
yarn hardhat run scripts/deploy.js --network localhost
And you should see transactions happen in your terminal that is running yarn hardhat node
Important localhost note
If you use metamask with a local network, everytime you shut down your node, you'll need to reset your account. Settings -> Advanced -> Reset account. Don't do this with a metamask you have real funds in. And maybe don't do this if you're a little confused by this.
-
Setup environment variables
You'll want to set your
RINKEBY_RPC_URL
andPRIVATE_KEY
as environment variables. You can add them to the.env
file.PRIVATE_KEY
: The private key of your account (like from metamask).- You can learn how to export it here.
RINKEBY_RPC_URL
: This is url of the rinkeby testnet node you're working with. You can get setup with one for free from Alchemy
-
Get testnet ETH
Head over to faucets.chain.link and get some tesnet ETH. You should see the ETH show up in your metamask.
-
Deploy
yarn hardhat run scripts/deploy.js --network rinkeby
yarn hardhat run scripts/deploy.ts --network rinkeby
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 environment variable named ETHERSCAN_API_KEY
. You can put it into your .env
file.
In it's current state, if you have your api key set, it will auto verify rinkeby contracts!