This is a basic repo to get anyone started with a dApp. This repo has the following features:
- Two basic Ethereum smart contracts called
BasicStorageandBasicStorageV2 - Scripts to deploy
BasicStorageand upgrade this smart contract toBasicStorageV2 - Upgrading is done with Hardhat using the Transparent Proxy Pattern
- Smart contract have a testbed of unit tests
- Functions in the smart contract are reserved by the
onlyOwnermodifier so only the deployer can execute them - Ability to deploy and upgrade on Sepolia and zkEVM Testnet
- Basic React app that reads the
BasicStorageV2smart contract - Basic React unit test
Basic setup
npm install
npm install --save-dev hardhat
npx hardhat
npx hardhat compile
npx hardhat test
npm test
Update secres.json
- Replace
<MNEMONIC>with the one from your wallet that has testnet tokens - Replace
<API_KEY>with your alechemy.com API key for Sepolia - Replace
<ACCOUNT_PRIVATE_KEY>with your private key for your wallet
- Run:
npx hardhat run --network sepolia scripts/eth/deploy_upgradeable_basic_storage.js
- Update
scripts/eth/upgrade_basic_storage.jswith the address from #1 where it says<ADDRESS_HERE> - Run:
npx hardhat run --network sepolia scripts/eth/upgrade_basic_storage.js
- On the command line run:
npx hardhat console --network sepolia
- From Deploying to Sepolia, replace in the code below with the deployed address. Note that persisting any value in a smart contract via store() or storeOpenValue() may take up to 10 seconds.
address = '0x48209332d458224afD66431c9d42bf060aadc4ee'
const BasicStorageV2 = await ethers.getContractFactory('BasicStorageV2');
const basicStorage = await BasicStorageV2.attach(address);
(await basicStorage.retrieve()).toString(); // should be 0
(await basicStorage.store(100));
(await basicStorage.retrieve()).toString(); // should be 100
(await basicStorage.increment())
(await basicStorage.retrieve()).toString(); // should be 101
(await basicStorage.retrieveOpen()).toString(); // should be 0
(await basicStorage.storeOpenValue(200));
(await basicStorage.retrieveOpen()).toString(); // should be 200
In one window run:
npx hardhat node
Then, in another window do the following:
- Run:
npx hardhat run --network localhost scripts/eth/deploy_upgradeable_basic_storage.js
- Update
scripts/eth/upgrade_basic_storage.jswith the address from #1 where it says<ADDRESS_HERE> - Run:
npx hardhat run --network localhost scripts/eth/upgrade_basic_storage.js
- To execute commands against your local blockchain, similar to the section Execute against Sepolia, run the following :
npx hardhat console --network sepolia
- Make sure that you have enough Eth on zkEVM testnet.
- Replace
<ACCOUNT_PRIVATE_KEY>insecrets.jsonwith the private key for your wallet. Note that you can just use<MNEMONIC>just like with the Eth scripts, but for variety and as an example I decided to use<ACCOUNT_PRIVATE_KEY>. You would only need to updatehardhat.config.jsfor the zkEVM network to usemnemonic. - Run
npx hardhat run scripts/zkevm/deploy.js --network zkEVM
- Deploy the smart contract
- After deployment replace
<DEPLOYED_ADDRESS>at the top ofsrc/App.js. - Make the ABI available from the build to your react app. Run the following from the root to make a copy of the ABI so your react app has access to it:
cp -R artifacts/contracts src/contracts
- npm start
I used the following resources to pull together this repo:
