let payment <- acct.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault)!.withdraw(amount: price) as! @FlowToken.Vault saleCollection.purchase(id: id, receipientCollection: recipientCollection, payment: <- payment) }
my whole cadence code :https://github.com/Wiswa14/flow-MarketPlace/tree/master
This transaction code is for purchase a nft from a collection public path
You are borrowing the
saleCollectionlike this:It looks like the error is because it is an optional type (the
?at the end of the type), and you are not unwrapping it. The reason it is an optional is because the borrow will fail if the user does not have a sale collection there.There are two ways to unwrap the optional:
1. Force-Unwrap Operator (
!)When you borrow the
saleCollection, put a force-unwrap operator!at the end and it will become a non-optional type, like so:2.
panicYou can also put a
panicstatement to unwrap the optional and put a more clear error message: