Approve Pattern
Based on ERC20 token learn the rules for transfering tokens, including the approval pattern when a user wishes to instruct a vendor contract to sell a proportion of their tokens.
ERC20 has two types of transfers.
- transfer tokens from the total supply of the contract vendor address to another address
- transferFrom used transfer tokens between any two users.
Most dapps implement the transferFrom functionality.
Risks
Scaffold Eth Challenge
Create a Dapp that lets users purchase your ERC20 token, transfer it, and sell it back to the vendor.
Learn about the approve pattern for ERC20 and how contract to contract interactions work.
Steps | Notes |
---|---|
SC: Mint tokens to user address from Scaffold Eth UI | Done |
App: Check balance | Done |
App: Transfer tokens to another account (e.g incognito browser) | Issue, could not get transfer to work |
SC: Change address mint address to return to sender | Done |
SC: Vendor.sol create a buy function | Done |
SC: Vendor.sol create a withdraw function | Done |
SC: Vendor.sol create a sell function | Done |
SC: Run tests | Done |
App: Enable interaction through UI | Uncomment code |
App: Improve UI UX | Todo |
App: Deploy Smart Contract to a Testnet | Todo |
Hardhat: Test Smart Contract Deployment | Todo |
App: Deploy Web App | Todo |
Checkpoint 2
Create YourToken.sol from ERC20 standard.
- Mint to the address from localhost:3000
- Check the balanceOf() your frontend address
- Transfer() your token to another account - Not working?
Mint tokens
Address taken from default user in the Scaffold Eth app.
_mint( 0xef6e7B541c239F90567F1F0dc15D0c4087603F54 , 1000 * 10 ** 18);