approve

approve

The approve method, within the ERC-721 token standard, empowers the owner of a specific non-fungible token (NFT) to grant permission to another Ethereum address for transferring the said NFT on their behalf. Each NFT can have only one approved address at any given time. This method is an integral part of the ERC721Instance object, accessible through suitable client libraries such as ZkyugaClient.

Method Signature

async approve(userAddress: string, tokenId: string, signer: WalletSigner): Promise<TransactionResponse>

Parameters

Parameter
Type
Description

userAddress

string

The Ethereum address to which permission is granted for transferring the specific ERC-721 token.

tokenId

string

The unique identifier of the ERC-721 token for which the approved address is being set.

signer

WalletSigner

The wallet signer instance responsible for signing the transaction. This should be associated with the owner of the specified token.

Returns

  • A Promise resolving to a TransactionResponse object. This object furnishes transaction details like its status, transaction hash, and others.

Usage Example

Commence by instantiating your desired ERC-721 token contract:

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

Then, utilize the approve method to establish an approval:

const userAddressToApprove = "0xExampleUserAddressHere";
const tokenIdToApprove = "1015"; // Example token ID
const signer = zkyugaClient.createWalletSigner("your private key");

const transactionResponse = await erc721.approve(userAddressToApprove, tokenIdToApprove, signer);
console.log(`Transaction Hash: ${transactionResponse.hash}`);

Notes

  • Only the current owner of an ERC-721 token can set approvals for it.

  • Setting a new approved address will override any previous approval for that specific token.

  • Always handle your private keys with care. The signer should be created and used securely, avoiding exposure in client-side or insecure environments.


Last updated