Skip to main content

Resource Collection

resource Collection {

ownedNFTs: {UInt64: NonFungibleToken.NFT}
}

The resource that will be holding the NFTs inside any account. In order to be able to manage NFTs any account will need to create an empty collection first

Implemented Interfaces:

  • ExampleNFTCollectionPublic
  • NonFungibleToken.Provider
  • NonFungibleToken.Receiver
  • NonFungibleToken.CollectionPublic
  • MetadataViews.ResolverCollection

Initializer​

func init()

Functions​

fun withdraw()​

func withdraw(withdrawID UInt64): NonFungibleToken.NFT

Removes an NFT from the collection and moves it to the caller

Parameters:

  • withdrawID : The ID of the NFT that wants to be withdrawn

Returns: The NFT resource that has been taken out of the collection


fun deposit()​

func deposit(token NonFungibleToken.NFT)

Adds an NFT to the collections dictionary and adds the ID to the id array

Parameters:

  • token : The NFT resource to be included in the collection

fun getIDs()​

func getIDs(): [UInt64]

Helper method for getting the collection IDs

Returns: An array containing the IDs of the NFTs in the collection


fun borrowNFT()​

func borrowNFT(id UInt64): &NonFungibleToken.NFT

Gets a reference to an NFT in the collection so that the caller can read its metadata and call its methods

Parameters:

  • id : The ID of the wanted NFT

Returns: A reference to the wanted NFT resource


fun borrowExampleNFT()​

func borrowExampleNFT(id UInt64): &ExampleNFT.NFT?

Gets a reference to an NFT in the collection so that the caller can read its metadata and call its methods

Parameters:

  • id : The ID of the wanted NFT

Returns: A reference to the wanted NFT resource


fun borrowViewResolver()​

func borrowViewResolver(id UInt64): &AnyResource{MetadataViews.Resolver}

Gets a reference to the NFT only conforming to the {MetadataViews.Resolver} interface so that the caller can retrieve the views that the NFT is implementing and resolve them

Parameters:

  • id : The ID of the wanted NFT

Returns: The resource reference conforming to the Resolver interface