transferOwnership

The transferOwnership method is a feature specific to the ERC-721 token standard, enabling the current owners of non-fungible tokens (NFTs) to transfer ownership of those tokens to other Ethereum addresses. This operation is fundamental for actions like selling, gifting, or otherwise passing the rights and control of individual NFTs to different parties. The method is accessible through the ERC721Instance object, typically provided by client libraries such as ZkyugaClient.

Method Signature

async transferOwnership(to: string, tokenId: string, signer: WalletSigner): Promise<TransactionResponse>

Parameters

Parameter
Type
Description

to

string

The Ethereum address to which the ownership of the specified ERC-721 token should be transferred. Upon completion of the transfer, this address becomes the new owner of the token.

tokenId

string

The unique identifier associated with the particular ERC-721 token being transferred. This ID distinguishes individual non-fungible tokens within the contract.

signer

WalletSigner

An instance responsible for signing the transfer transaction. This is typically created using various mechanisms or methods provided by client libraries, ensuring that the initiator has the authority to transfer the token associated with the provided tokenId.

Returns

  • A Promise resolving to a TransactionResponse object, which furnishes details about the transaction, including its status, transaction hash, and more.

Usage Example

Begin by obtaining an instance of the desired ERC-721 token contract:

const erc721 = zkyugaClient.getERC721Instance("your ERC-721 contract address here");

Then, employ the transferOwnership method to transfer an NFT:

const recipient = "0xRecipientAddressHere";
const tokenId = "1010"; // Replace with your token ID
const signer = zkyugaClient.createWalletSigner("your private key");

const transactionResponse = await erc721.transferOwnership(recipient, tokenId, signer);
console.log(`Transaction Hash: ${transactionResponse.hash}`);

Notes

  • Prior to initiating the transfer, ensure that the signer possesses ownership of the token specified by tokenId.

  • Always handle the signer securely to prevent the exposure of private keys in insecure environments..

  • The function name transferOwnership may vary among different ERC-721 implementations. Some contracts might use alternative names such as transferFrom for this functionality. Always refer to the specific ERC-721 contract's documentation for precise details.


Last updated