aacoimbra

Transaction

Dec 29th, 2023 (edited)
1,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. import "Collectables"
  2. import "NonFungibleToken"
  3. import "MetadataViews"
  4.  
  5. transaction(packID: UInt32, cardID: UInt32) {
  6.     // local variable for the admin reference
  7.     let adminRef: &Collectables.Admin
  8.     let receiverRef: &AnyResource{NonFungibleToken.CollectionPublic}
  9.  
  10.     prepare(admin: AuthAccount, user: AuthAccount) {
  11.         // borrow a reference to the Admin resource in storage
  12.         self.adminRef = admin.borrow<&Collectables.Admin>(from: Collectables.AdminStoragePath)!
  13.  
  14.         if user.borrow<&Collectables.Collection>(from: Collectables.NftCollectionStoragePath) == nil {
  15.            
  16.             let collection  <- Collectables.createEmptyCollection()
  17.  
  18.             user.save(<- collection, to: Collectables.NftCollectionStoragePath)
  19.  
  20.             user.link<&{NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic, MetadataViews.ResolverCollection}>(Collectables.NftCollectionPublicPath, target: Collectables.NftCollectionStoragePath)
  21.         }
  22.  
  23.         self.receiverRef = user.getCapability(Collectables.NftCollectionPublicPath).borrow<&{NonFungibleToken.CollectionPublic}>()!
  24.     }
  25.  
  26.     execute {
  27.  
  28.         let packRef: &Collectables.Pack = self.adminRef.borrowPack(packID: packID)
  29.  
  30.         let mintedCard: @NonFungibleToken.NFT <-! packRef.mintNft(cardID: cardID) as! @NonFungibleToken.NFT
  31.  
  32.         self.receiverRef.deposit(token: <- mintedCard )
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment