Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import "Collectables"
- import "NonFungibleToken"
- import "MetadataViews"
- transaction(packID: UInt32, cardID: UInt32) {
- // local variable for the admin reference
- let adminRef: &Collectables.Admin
- let receiverRef: &AnyResource{NonFungibleToken.CollectionPublic}
- prepare(admin: AuthAccount, user: AuthAccount) {
- // borrow a reference to the Admin resource in storage
- self.adminRef = admin.borrow<&Collectables.Admin>(from: Collectables.AdminStoragePath)!
- if user.borrow<&Collectables.Collection>(from: Collectables.NftCollectionStoragePath) == nil {
- let collection <- Collectables.createEmptyCollection()
- user.save(<- collection, to: Collectables.NftCollectionStoragePath)
- user.link<&{NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic, MetadataViews.ResolverCollection}>(Collectables.NftCollectionPublicPath, target: Collectables.NftCollectionStoragePath)
- }
- self.receiverRef = user.getCapability(Collectables.NftCollectionPublicPath).borrow<&{NonFungibleToken.CollectionPublic}>()!
- }
- execute {
- let packRef: &Collectables.Pack = self.adminRef.borrowPack(packID: packID)
- let mintedCard: @NonFungibleToken.NFT <-! packRef.mintNft(cardID: cardID) as! @NonFungibleToken.NFT
- self.receiverRef.deposit(token: <- mintedCard )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment