getApproved
The getApproved
method, specific to the ERC-721 token standard, facilitates users in querying the Ethereum address (if any) currently authorized to transfer a particular ERC-721 token. In this standard, each non-fungible token (NFT) can only be approved for transfer to one address at a time, apart from its owner, who always retains the privilege to transfer the token. This functionality is integral to the ERC721Instance
object, which can be accessed via appropriate methods provided by client libraries, such as ZkyugaClient
.
Method Signature
async getApproved(tokenId: string): Promise<string>
Parameters
tokenId
string
The unique identifier of the ERC-721 token for which you intend to verify the approved address.
Returns
A
Promise
resolving to an Ethereum address string. If no address is authorized, it might return the zero address (0x0000000000000000000000000000000000000000).
Usage Example
First, initialize the desired ERC-721 token contract:
const erc721 = zkyugaClient.getERC721Instance("your ERC-721 contract address here");
Then, utilize the getApproved
method with a specific token ID:
const tokenId = "12345"; // Example token ID
const approvedAddress = await erc721.getApproved(tokenId);
if (approvedAddress == "0x0000000000000000000000000000000000000000") {
console.log(`Token ID ${tokenId} has no approved address.`);
} else {
console.log(`Token ID ${tokenId} is approved for transfer by: ${approvedAddress}`);
}
Notes
Keep in mind that even if a token has an approved address, its owner can always transfer it without additional approvals.
For user interfaces or frontend applications, consider gracefully handling scenarios where the token lacks any approved address (e.g., by providing informative feedback to users).
Last updated