Develop simple store:
- The administrator (owner) of the store should be able to add new products and the quantity of them.
- The administrator should not be able to add the same product twice, just quantity.
- Buyers (clients) should be able to see the available products and buy them by their id.
- Buyers should be able to return products if they are not satisfied (within a certain period in blocktime: 100 blocks).
- A client cannot buy the same product more than one time.
- The clients should not be able to buy a product more times than the quantity in the store unless a product is returned or added by the administrator (owner)
- Everyone should be able to see the addresses of all clients that have ever bought a given product.
git clone https://github.com/Nedick/solidity-simple-store.git
cd solidity-simple-store
yarn
yarn hardhat deploy
yarn hardhat coverage
yarn hardhat test
To check linting / code formatting:
yarn lint
or, to fix:
yarn lint:fix
- Setup environment variabltes
You'll want to set your RINKEBY_RPC_URL
and PRIVATE_KEY
as environment variables.
PRIVATE_KEY
: The private key of your account (like from metamask). NOTE: FOR DEVELOPMENT, PLEASE USE A KEY THAT DOESN'T HAVE ANY REAL FUNDS ASSOCIATED WITH IT.- 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 & LINK. You should see the ETH and LINK show up in your metamask. You can read more on setting up your wallet with LINK.
Then run:
yarn hardhat deploy --network rinkeby --tags all
To get a USD estimation of gas cost, you'll need a COINMARKETCAP_API_KEY
environment variable. You can get one for free from CoinMarketCap.
Then, uncomment the line coinmarketcap: COINMARKETCAP_API_KEY,
in hardhat.config.js
and set REPORT_GAS
environment variable to get the USD estimation. Just note, everytime you run your tests it will use an API call, so it might make sense to have using coinmarketcap disabled until you need it. You can disable it by just commenting the line back out.
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.
In it's current state, if you have your api key set, it will auto verify rinkeby contracts!
However, you can manual verify with:
yarn hardhat verify --constructor-args arguments.ts DEPLOYED_CONTRACT_ADDRESS
- Add unit tests for contracts
- Add scripts for contract interaction on local or test network
- Refactor the code to reduce gas costs and clean up the bugs
- Find out how to use Multicall contract in the context of the task
- Deploy contracts on actual test network like Rinkeby
- Add user friendly front-end using ethers.js and next.js ?