Implementation
Key concepts
- ERC-20 ABI - Minimal ABI containing only the transfer function
- Function encoding - Uses
encodeFunctionDatafrom viem to encode the function call - Amount handling - Amount should be in the token’s smallest unit (considering decimals)
- Contract interaction - Sends transaction to the token contract address with encoded data
Important notes
Make sure the user has approved your contract to spend tokens if you’re building a dApp that needs to transfer tokens on behalf of users.
Next steps
NFT Minting
Learn how to mint NFTs
Multi-Step Flow
Handle approve + transfer flows