metaplex-foundation / js

A JavaScript SDK for interacting with Metaplex's programs
357 stars 182 forks source link

Can't seem to access `delegateAddress` when using `findAllBy` methods #301

Closed GrimLothar closed 2 years ago

GrimLothar commented 2 years ago

I noticed that while all the findBy methods include an output of NftWithToken, the findAllBy don't

I also noticed that the delegateAddress is only available in the Token model.

So that's basically not allowing me to check if the NFTs being returned by findAllByOwner have a delegateAddress or not.

Is there something I'm missing to be able to check the delegateAddress when when using findAllBy methods?

Thank you!

lorisleiva commented 2 years ago

Hi there 👋

Yes, that's because when fetching multiple NFTs from the blockchain, it isn't performant to fetch additional accounts, such as the token account, as well.

Instead, it simply returns the Metadata model which can transformed into a NftWithToken using the nfts().load() operation. This is explained in the readme.

GrimLothar commented 2 years ago

Hey @lorisleiva thank you for your reply!

I'm probably making wrong assumptions here, but running nfts().load() on hundreds of individual accounts sounds less performant than running the native web3 method getParsedTokenAccountsByOwner. (100s calls vs 1).

lorisleiva commented 2 years ago

It depends on the information you're looking for. The idea with this operation is that you lazy load the metadata accounts and then load the full data (including fetching its JSON metadata) as and when you need it. It would not be performant to load the URIs and Token accounts of all of them in one go (especially has we don't control where the URIs point from).

A good example for using this operation is displaying NFTs in a web page. For instance, you may want to paginate that list and display more information on the NFT whenever the user clicks on it.

Now, if you're mostly interested in the token accounts to find out about delegate authorities then that operation is less useful to you and using the RPC method you mentioned should be more performant.

Something the SDK could support in the future is a similar operation on the Token module so you could do something like metaplex.tokens().findAllByOwner() and that would return a list of Token instead of metadata.

I hope this helps.

GrimLothar commented 2 years ago

Awesome, thank you for taking the time to confirm which route to take (for now, until the SDK supports that other method that sounds amazing)

Thanks!