Move.

Post

Share your knowledge.

yhant3.
Apr 07, 2025
Expert Q&A

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
0
3
Share
Comments
.

Answers

3
kryptoschain.
Apr 7 2025, 20:34

To 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.

0
Comments
.
deriss.
Apr 7 2025, 20:36

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.

0
Comments
.
DuAn.
Apr 7 2025, 21:52

You actually don't need this function as you can directly call tx.transferObjects within a PTB.

0
Comments
.

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.

148Posts231Answers
Sui.X.Peera.

Earn Your Share of 1000 Sui

Gain Reputation Points & Get Rewards for Helping the Sui Community Grow.

Reward CampaignJune
    We use cookies to ensure you get the best experience on our website.
    More info