A ➜ approve(spender, amount)
B ➜ transferFrom(sender, buyer, amount)
allowance(address tokenOwner, address spender)
I am seeing that this function can be call only if the person know the address of the tokenOwner and token of the spender. What if
1) I as a spender want to know the list of people who allow me to spend their token without they notify us?
2) I as an owner want to keep track of approve spender and amount list?
I am expecting something like getAllowanceList(tokenOwner) and getAllowanceList(spender)
Is that supported? If not, why is it not supported?
Best Answer
According to the ERC20 specification, whenever the
approve()
function is called, anApproval
event needs to fire with the details of the approval:Thus if you want to know all of the approvals that have been made for a specific ERC20 token, you can look at the event logs for that contract filtering on the approvals.
You could similarly track the
Transfer
event to keep track of who has redeemed their allowances.myContract.getPastEvents()
should enable you to do both of these tasks with Web3.js v1.0.The ERC20 standard only defines a minimum interface required to meet the standard, and does not necessarily define the specific implementation of the standard. Some contract creators could absolutely add this functionality in addition to the other standard functions, but it would be an extra as it is not defined in the specification. Ultimately, holding and manipulating this data costs gas, and if you want to create a performant smart contract, you want to minimize extras like this as much as possible. In this situation, using the event log is a more cost effective alternative to storing this data on-chain.