AlphaWallet / AlphaWallet/alpha-wallet-ios
Support ERC721Enumerable interface
- 主要语言
- Swift
- 星标
- 631
- 派生
- 384
- PR 合并指标
- 30 天内没有已合并 PR
描述
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).
贡献指南
评估
这个 Issue 还没有评估数据。