1

I'm trying to get the metadata for the Genesis collection from the DriverzNFT contract

this is the script I have

import DriverzNFT from 0xa039bd7d55a96c0c
import NonFungibleToken from 0x1d7e57aa55817448
import MetadataViews from 0x1d7e57aa55817448

pub fun main(address: Address): [&DriverzNFT.NFT] {
    let collection = getAccount(address).getCapability(DriverzNFT.CollectionPublicPath)
                        .borrow<&DriverzNFT.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}>(DriverzNFT.CollectionPublic)
                        ?? panic("Can't get collection")

    let returnVals: [&DriverzNFT.NFT] = []

    let ids = collection.getIDs()
    for id in ids {
        returnVals.append(collection.borrowDriverzNFT(id: id))
    }

    return returnVals
}

Something is wrong here. I checked the transaction to see where the NFTs are stored and linked when they're sent over, and I checked the contract to see how the collection interface is built. Does anyone have any ideas why I can't pull this data???

The cadence script that I tried is written above. I used the following script to check if the NFT exists in an account:

import NonFungibleToken from 0x1d7e57aa55817448 import MetadataViews from 0x1d7e57aa55817448 import DriverzNFT from 0xa039bd7d55a96c0c

pub fun main(address: Address): Bool { return getAccount(address) .getCapability<&DriverzNFT.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}>(DriverzNFT.CollectionPublicPath) .check() }

And, this one worked and said that the NFT did exist in my account. But, why then wouldn't the other script share the data? Expecially if I am using the same path in the getCapability object.

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
RMT Books
  • 19
  • 2

1 Answers1

1

Great question. There are a few errors I get when I run your first script:

  1. error: value of type DriverzNFT has no member CollectionPublic

This error is because of this part of the script: DriverzNFT.CollectionPublic. You can actually delete this part because you already supply a public path in that line. Here is the corrected version:

let collection = getAccount(address).getCapability(DriverzNFT.CollectionPublicPath)
                .borrow<&DriverzNFT.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}>() 
                ?? panic("Can't get collection")
  1. error: member of restricted type is not accessible: borrowDriverzNFT

This is coming from this here: collection.borrowDriverzNFT(id: id). The function borrowDriverzNFT is only accessible through the DriverzNFT.CollectionPublic interface, but you forget to include that type in your capability earlier on!

Here is a complete corrected version of your script:

import DriverzNFT from 0xa039bd7d55a96c0c 
import NonFungibleToken from 0x1d7e57aa55817448 
import MetadataViews from 0x1d7e57aa55817448

pub fun main(address: Address): [&DriverzNFT.NFT] { 

  let collection = getAccount(address).getCapability(DriverzNFT.CollectionPublicPath)
                .borrow<&DriverzNFT.Collection{DriverzNFT.CollectionPublic, NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}>() 
                ?? panic("Can't get collection")

  let returnVals: [&DriverzNFT.NFT] = []

  let ids = collection.getIDs()
  for id in ids {
      returnVals.append(collection.borrowDriverzNFT(id: id))
  }

  return returnVals

}
Jacob Tucker
  • 132
  • 7