AlphaWallet / AlphaWallet/alpha-wallet-ios

Support ERC721Enumerable interface

Aperta
#5,413 2 commenti 0 reazioni 1 assegnatario Rivendicata da @hboon Vedi su GitHub
Lingua principale
Swift
Stelle
631
Fork
384
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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).

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.