Post
Share your knowledge.
How to ensure only NFT owner can transfer it in a contract?
Hey everyone! I'm working on implementing an NFT contract and want to make sure that only the rightful owner of the NFT can transfer it. I have this function for transferring:
public fun transfer(
nft: DevNetNFT, recipient: address, _: &mut TxContext
) {
transfer::public_transfer(nft, recipient)
}
Is this checking done within the public_transfer
method, or do I need to add additional logic?
- Move CLI
Answers
3To clarify further, it's not specifically the public_transfer
that is checking ownership, but rather the Sui transaction semantics. For a transaction to accept an object as input, you must have ownership, meaning the sender's address must match the owner address on the object. Shared objects, however, treat everyone as an 'owner' for the purpose of transactions.
CHECKWITHEGORBefore the transfer of an NFT, the public_transfer
function checks whether the sender holds the NFT. Thus, the logic is indeed built into the public_transfer
method.
You actually don't need this function as you can directly call tx.transferObjects
within a PTB.
Do you know the answer?
Please log in and share it.
Move is an executable bytecode language used to implement custom transactions and smart contracts.