transferOwnership
The transferOwnership
method is specific to the ERC-721 token standard, allowing current owners of a non-fungible token (NFT) to transfer ownership of that token to another Ethereum address. This operation is vital for selling, gifting, or otherwise transferring the rights and control of an individual NFT. It is a part of the ERC721Instance
object, accessible through client libraries like EdexaClient
.
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 ERC-721 token should be transferred. This address will become the new owner of the specified token. |
tokenId | string | The unique identifier associated with the specific ERC-721 token being transferred. This ID differentiates 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 right to transfer the token associated with the provided tokenId. |
Returns
- A
Promise
resolving to aTransactionResponse
object. This object provides details about the transaction, such as its status, transaction hash, etc.
Usage Example
First, acquire an instance of the desired ERC-721 token contract:
const erc721 = edexaClient.getERC721Instance("your ERC-721 contract address here");
Then, use the transferOwnership
method to transfer an NFT:
const recipient = "0xRecipientAddressHere";
const tokenId = "12345"; // Replace with your token ID
const signer = edexaClient.createWalletSigner("your private key");
const transactionResponse = await erc721.transferOwnership(recipient, tokenId, signer);
console.log(`Transaction Hash: ${transactionResponse.hash}`);
Notes
Ensure that the signer has ownership of the token specified by
tokenId
before attempting the transfer.For security reasons, always handle the
signer
securely and avoid exposing private keys in client-side or insecure environments.The
transferOwnership
function name may differ among various ERC-721 implementations. Some contracts might usetransferFrom
or similar names for this functionality. Always refer to the specific ERC-721 contract's documentation.