This is a simple smart contract made by using ethers.js, which allows users to store a number and retrieve it. The users are mapped to the numbers respectively.
Clone this repo
git clone https://github.com/0xSanyam/ethers-simple-storage
Then install dependencies
yarn
Note: You'll notice in
package.json
we are using"solc": "0.8.7-fixed"
. Usually, you'll just be able to do"solc": "0.8.7"
to get a specific version, but there is an issue with that one.
-
Run your ganache local chain, by hitting
quickstart
on your ganache applicationSave the workspace. This way, next time you open ganache you can start the workspace you've created, otherwise you'll have to redo all the steps below.
-
Copy the
RPC SERVER
from ganache, and place it into your.env
file..env
Example:RPC_URL = http://0.0.0.0:8545
-
Hit the key on one of the accounts, and copy the key you see and place it into your
.env
file..env
Example:PRIVATE_KEY=15e691a01da28afab4445f2e5f0fafbcb81af237bcbe3b2e46ad968b3643fd73
-
Compile your code
Run
yarn compile
You'll see files
SimpleStorage_sol_SimpleStorage.abi
andSimpleStorage_sol_SimpleStorage.bin
be created. -
Run your application
node deploy.js
Make sure you have a metamask or other wallet, and export the private key.
IMPORTANT
Use a Metamask that doesn't have any real funds in it. Just in case you accidentally push your private key to a public place.
-
Export your private key and place it in your
.env
file, as done above. -
Go to Alchemy and create a new project on the testnet of choice (e.g. Rinkeby)
-
Grab your URL associated with the testnet, and place it into your
.env
file. -
Make sure you have testnet ETH in your account. You should get testnet ETH for the same testnet that you made a project in Alchemy.
-
Run
node deploy.js
ts-node deploy.ts