AlphaWallet / AlphaWallet/alpha-wallet-ios
Support ERC721Enumerable interface
- Langage dominant
- Swift
- Étoiles
- 631
- Forks
- 384
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
Why: Speeds up and simplifies balance query for ERC721.
First detect the ERC721Enumerable interface in your Token interface check:
ERC721Enumerable Interface hash: ```0x780e9d63```
Then using this contract call:
```function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256)```
Walk the balance index sequentially to fetch all ERC721 tokenIds for an address.
You will need the ```balanceOf(address owner)``` to find the total balance held, then just do 0 -> (total balance -1) and use that for the ```index``` in the ```tokenOfOwnerByIndex``` call.
Eg:
```balanceOf(0x123456...)```
returns a balance of 3
```
for (uint i = 0; i < balanceOf(0x123456...); i++)
{
balanceArray[i] = tokenOfOwnerByIndex(0x123456..., i);
}
```
balanceArray could be { 6345, 1295, 5566 }
Which is your TokenId list.
See:
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721Enumerable.sol#:~:text=function%20tokenOfOwnerByIndex(,%7D
Note, for AW Android this doesn't completely replace the event log search, because we still want to find events to populate the activity pane. It does mean though that you don't need to check that the address still holds the tokenId before adding it (after finding the tokenId via a receive log).
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.