How to implement token revoke feature?
Created by Qiwei on 8/26/2022 · Edited on 7/5/2026
1. Learn Token Basics
- https://docs.openzeppelin.com/contracts/4.x/tokens
- Much of the confusion surrounding tokens comes from two concepts getting mixed up: token contracts and the actual tokens.
- A token contract is simply an Ethereum smart contract. "Sending tokens" actually means "calling a method on a smart contract that someone wrote and deployed". At the end of the day, a token contract is not much more than a mapping of addresses to balances, plus some methods to add and subtract from those balances.
- It is these balances that represent the tokens themselves. Someone "has tokens" when their balance in the token contract is non-zero. That’s it! These balances could be considered money, experience points in a game, deeds of ownership, or voting rights, and each of these tokens would be stored in different token contracts.
- How is a Token stored?
- FT
- NFT
- ERC 721: eips.ethereum.org/EIPS/eip-721
- ERC 1155: eips.ethereum.org/EIPS/eip-1155
2. Token Approval Revoke
- how etherscan does it: etherscan.io/tokenapprovalchecker
- why this exist?
- how to implement?
-
eth json-rpc api: ethereum.org/en/developers/docs/apis/json-rpc/#eth_sendtransaction
-
use ‘eth json-rpc api’ in metamask: docs.metamask.io/guide/rpc-api.html#table-of-contents
MetaMask uses the
ethereum.request(args)method to wrap an RPC API. -
basic usage guide: docs.metamask.io/guide/sending-transactions.html#example
-
- react lib: wagmi.sh for connect wallet, easy-to-use hooks for everything