github.com/DapperCollectives/CAST/backend@v0.0.0-20230921221157-1350c8be7c96/main/cadence/transactions/transfer_nft.cdc (about) 1 import NonFungibleToken from 0xf8d6e0586b0a20c7 2 import ExampleNFT from 0xf8d6e0586b0a20c7 3 4 /// This transaction is for transferring and NFT from 5 /// one account to another 6 7 transaction(recipient: Address, withdrawID: UInt64) { 8 9 /// Reference to the withdrawer's collection 10 let withdrawRef: &ExampleNFT.Collection 11 12 /// Reference of the collection to deposit the NFT to 13 let depositRef: &{NonFungibleToken.CollectionPublic} 14 15 prepare(signer: AuthAccount) { 16 // borrow a reference to the signer's NFT collection 17 self.withdrawRef = signer 18 .borrow<&ExampleNFT.Collection>(from: ExampleNFT.CollectionStoragePath) 19 ?? panic("Account does not store an object at the specified path") 20 21 // get the recipients public account object 22 let recipient = getAccount(recipient) 23 24 // borrow a public reference to the receivers collection 25 self.depositRef = recipient 26 .getCapability(ExampleNFT.CollectionPublicPath) 27 .borrow<&{NonFungibleToken.CollectionPublic}>() 28 ?? panic("Could not borrow a reference to the receiver's collection") 29 30 } 31 32 execute { 33 34 // withdraw the NFT from the owner's collection 35 let nft <- self.withdrawRef.withdraw(withdrawID: withdrawID) 36 37 // Deposit the NFT in the recipient's collection 38 self.depositRef.deposit(token: <-nft) 39 } 40 41 post { 42 !self.withdrawRef.getIDs().contains(withdrawID): "Original owner should not have the NFT anymore" 43 self.depositRef.getIDs().contains(withdrawID): "The reciever should now own the NFT" 44 } 45 }