getApproved
The getApproved
method is specific to the ERC-721 token standard. It allows users to query which Ethereum address (if any) is currently approved to transfer a specific ERC-721 token. Each non-fungible token (NFT) can have only one approved address at a time, besides its owner who can always transfer the token. This method is part of the ERC721Instance
object, which can be acquired via an appropriate method of the client library (e.g., EdexaClient
or similar).
Method Signature
async getApproved(tokenId: string): Promise<string>
Parameters
Parameter | Type | Description |
---|---|---|
tokenId | string | The unique identifier of the ERC-721 token for which you want to check the approved address. |
Returns
- A
Promise
that resolves to an Ethereum address string. If no address is approved, this might return the zero address (0x0000000000000000000000000000000000000000
).
Usage Example
First, instantiate the desired ERC-721 token contract:
const erc721 = edexaClient.getERC721Instance("your ERC-721 contract address here");
Then, call the getApproved
method using 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
Remember that even if a token has an approved address, the owner of the token can always transfer it without any additional approvals.
If you're working with user interfaces or frontend applications, consider handling the scenario where the token does not have any approved address gracefully (e.g., by displaying a relevant message to the user).
The getApproved
method is specific to the ERC-721 token standard. It allows users to query which Ethereum address (if any) is currently approved to transfer a specific ERC-721 token. Each non-fungible token (NFT) can have only one approved address at a time, besides its owner who can always transfer the token. This method is part of the ERC721Instance
object, which can be acquired via an appropriate method of the client library (e.g., EdexaClient
or similar).
Method Signature
async getApproved(tokenId: string): Promise<string>
Parameters
tokenId
(string): The unique identifier of the ERC-721 token for which you want to check the approved address.
Returns
- A
Promise
that resolves to an Ethereum address string. If no address is approved, this might return the zero address (0x0000000000000000000000000000000000000000
).
Usage Example
First, instantiate the desired ERC-721 token contract:
const erc721 = edexaClient.getERC721Instance("your ERC-721 contract address here");
Then, call the getApproved
method using 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
Remember that even if a token has an approved address, the owner of the token can always transfer it without any additional approvals.
If you're working with user interfaces or frontend applications, consider handling the scenario where the token does not have any approved address gracefully (e.g., by displaying a relevant message to the user).