Skip to content

A simple smart contract made by using hardhat, which allows users to store a number and retrieve it

License

Notifications You must be signed in to change notification settings

0xSanyam/hardhat-simple-storage

Repository files navigation

Hardhat Simple Storage

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.

Quickstart

git clone https://github.com/0xSanyam/hardhat-simple-storage

Typescript

Typescript is also included in scripts, tasks and test section.

Usage

Deploy:

yarn hardhat run scripts/deploy.js

Deploy JS

yarn hardhat run scripts/deploy.ts

Deploy TS

Testing

yarn hardhat test

Test TS JS

Test Coverage

yarn hardhat coverage

Coverage

Estimate gas

You can estimate how much gas things cost by running:

yarn hardhat test

You'll see an output file called gas-report.txt

Local Deployment

If you'd like to run your own local hardhat network, you can run:

yarn hardhat node

Hardhat Node

And then in a different terminal

yarn hardhat run scripts/deploy.js --network localhost

Deploy Localhost

And you should see transactions happen in your terminal that is running yarn hardhat node

Node Log

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.

Deployment to a testnet or mainnet

  1. Setup environment variables

    You'll want to set your RINKEBY_RPC_URL and PRIVATE_KEY as environment variables. You can add them to the .env file.

    • PRIVATE_KEY: The private key of your account (like from metamask).
    • 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
  2. Get testnet ETH

    Head over to faucets.chain.link and get some tesnet ETH. You should see the ETH show up in your metamask.

  3. Deploy

    yarn hardhat run scripts/deploy.js --network rinkeby
    

    Deploy JS Testnet

    yarn hardhat run scripts/deploy.ts --network rinkeby
    

    Deploy TS Testnet

Verify on etherscan

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!

About

A simple smart contract made by using hardhat, which allows users to store a number and retrieve it

Resources

License

Stars

Watchers

Forks

Releases

No releases published