This is a light example of using create-react-app, hardhat, and ethers to interact with a Token contract and a Greeting contract in a React UI.
git clone https://github.com/maschad96/react-dapp-example
npm install
- Make any changes desired to the smart contracts
- Run
npx hardhat compile
to compile those changes down into./src/artifacts/
- Run
npx hardhat node
to run an Ethereum node locally. This will provide test ETH wallets to test with locally - Take the private key of the wallet you intend to test with, add it to
~/.zshrc/
asACCOUNT_KEY="{key}"
- Connect your MetaMask wallet to the 'Localhost 8545' network
- Import the test wallet used in Step 6 to your MetaMask wallet
- Run
npx hardhat run scripts/deploy.js --network localhost
to run the deploy script. This will deploy both the Greeter and Token contracts to their own Smart Contract Addresses on localhost. - Take the Token Address output from the console, open up MetaMask and add the Token by inputting the address into 'Token Contract Address'. The Token Symbol should autofill.
- Run
npm start
, starting up the React App.
This should open up an application where the greeting message in the Greeter contract can be changed, and retrieved with the Fetch Greeting message.
Additionally, the test wallet you use should receive the total supply of the token. You can send tokens from the UI by entering the test address you'd like to send tokens to, and the amount to send.