Token Module
Token module handles operations related to native tokens, ERC20 tokens, and NFTs.
To learn more about how to use the AI Agent SDK to interact with the token module, please visit AI Agent SDK Token Interaction.
2.1 Get Native Token Balance
Fetches the native token balance of a specific wallet address.
Function Name
get_native_balanceArguments
address (str): The address to get the balance for (CronosIds with the `.cro` suffix are supported, e.g. `xyz.cro`)Example Code
from crypto_com_developer_platform_client import Token balance = Token.get_native_balance('example-wallet') print(balance)
Returns
The balance of the native token.Errors
ValueError: If the Token class is not initialized with a Client instance.Example Return
{'status': 'Success', 'data': {'balance': 'example-balance'}}
Function Name
getNativeTokenBalanceArguments
{string} address: The wallet address (or CronosId `.cro`) to check.Example Code
import { Token } from '@crypto.com/developer-platform-client'; try { const balance = await Token.getNativeTokenBalance('example-wallet'); console.log(balance); } catch(err) { console.log(err); }
Returns
{Promise<ApiResponse<Balance>>}: A promise that resolves to the native token balance.Errors
{Error}: Throws an error if the request fails.Example Return
{ status: 'Success', data: { balance: 'example-balance' } }
2.2 Get ERC20 Token Balance
Fetches the ERC20 token balance of a wallet for a given ERC20 contract.
Function Name
get_erc20_balanceArguments
wallet_address (str): The address to get the balance for (CronosIds with the `.cro` suffix are supported, e.g. `xyz.cro`) contract_address (str): The contract address to get the balance for. block_height (str): The block height to get the balance for.Example Code
from crypto_com_developer_platform_client import Token balance = Token.get_erc20_balance('example-wallet', 'example-contract', 'latest') print(balance)
Returns
The balance of the ERC20 token.Errors
ValueError: If the Token class is not initialized with a Client instance.Example Return
{'status': 'Success', 'data': {'balance': 'example-balance'}}
Function Name
getERC20TokenBalanceArguments
{string} address: The wallet address (or CronosId `.cro`) to check. {string} contractAddress: The ERC20 contract address. {string} [blockHeight='latest']: Optional block height (default 'latest').Example Code
import { Token } from '@crypto.com/developer-platform-client'; try { const balance = await Token.getERC20TokenBalance('example-wallet', 'example-contract'); console.log(balance); } catch(err) { console.log(err); }
Returns
{Promise<ApiResponse<TokenBalance>>}: A promise that resolves to the ERC20 token balance.Errors
{Error}: Throws an error if the request fails.Example Return
{ status: 'Success', data: { balance: 'example-balance' } }
2.3 Transfer Token
Transfers native or ERC20 tokens.
Function Name
transfer_tokenArguments
to (str): The address to transfer the token to (CronosIds with the `.cro` suffix are supported, e.g. `xyz.cro`) amount (int): The amount of the token to transfer. contract_address (str): Optional. The contract address of the token to transfer.Example Code
from crypto_com_developer_platform_client import Token tx = Token.transfer_token('example-recipient', example-number) print(tx)
Returns
The transaction hash.Errors
ValueError: If the Token class is not initialized with a Client instance.Example Return
{'status': 'Success', 'data': {'magicLink': 'example-magic-link'}}
Function Name
transferArguments
{object} payload: Transfer parameters. {string} payload.to: Recipient address. {number} payload.amount: Amount to transfer. {string} [payload.contractAddress]: ERC20 contract address (optional)Example Code
import { Token } from '@crypto.com/developer-platform-client'; try { const result = await Token.transfer({ to: 'example-recipient', amount: example-number, contractAddress: 'example-contract-address'}); console.log(result); } catch(err) { console.log(err); }
Returns
{Promise<ApiResponse<MagicLinkData>>}: A promise that resolves to the transaction result.Errors
{Error}: Throws an error if the request fails.Example Return
{ status: 'Success', data: { magicLink: 'example-magic-link' } }
2.4 Wrap Token
Wrap tokens.
Function Name
wrap_tokenArguments
amount (float): The amount of the token to wrap.Example Code
from crypto_com_developer_platform_client import Token tx = Token.wrap_token(example-amount) print(tx)
Returns
The transaction hash.Errors
ValueError: If the Token class is not initialized with a Client instance.Example Return
{'status': 'Success', 'data': {'magicLink': 'example-magic-link'}}
Function Name
wrapArguments
{object} payload: Wrap parameters. {number} payload.amount: Amount to wrap.Example Code
import { Token } from '@crypto.com/developer-platform-client'; try { const result = await Token.wrap({ amount: example-number}); console.log(result); } catch(err) { console.log(err); }
Returns
{Promise<ApiResponse<MagicLinkData>>}: A promise that resolves to the wrap transaction result.Errors
{Error}: Throws an error if the request fails.Example Return
{ status: 'Success', data: { magicLink: 'example-magic-link' } }
2.5 Swap Token
Swap tokens.
Function Name
swap_tokenArguments
from_contract_address (str): The token to swap from. to_contract_address (str): The token to swap to. amount (int): The amount of the token to swap.Example Code
from crypto_com_developer_platform_client import Token tx = Token.swap_token('example-from', 'example-to', 'example-amount') print(tx)
Returns
The transaction hash.Errors
ValueError: If the Token class is not initialized with a Client instance.Example Return
{'status': 'Success', 'data': {'magicLink': 'example-magic-link'}}
Function Name
swapArguments
{object} payload: Swap parameters. {string} payload.fromContractAddress: Token being swapped. {string} payload.toContractAddress: Token to receive. {number} payload.amount: Amount to swap.Example Code
import { Token } from '@crypto.com/developer-platform-client'; try { const result = await Token.swap({ fromContractAddress: 'example-from-contract', toContractAddress: 'example-to-contract', amount: example-number }); console.log(result); } catch(err) { console.log(err); }
Returns
{Promise<ApiResponse<MagicLinkData>>}: A promise that resolves to the swap transaction result.Errors
{Error}: Throws an error if the request fails.Example Return
{ status: 'Success', data: { magicLink: 'example-magic-link' } }
2.6 Get ERC721 Token Balance
Fetches the ERC721 token balance for a wallet and contract.
Function Name
get_erc721_balanceArguments
wallet_address (str): The address to get the balance for. contract_address (str): The ERC721 contract address.Example Code
from crypto_com_developer_platform_client import Token balance = Token.get_erc721_balance('example-wallet','example-contract') print(balance)
Returns
The ERC721 token balance.Errors
ValueError: If the Token class is not initialized with a Client instance.Example Return
{'status': 'Success', 'data': {'balance': 'example-balance'}}
Function Name
getERC721TokenBalanceArguments
{string} walletAddress: Wallet address to check. {string} contractAddress: ERC721 contract address.Example Code
import { Token } from '@crypto.com/developer-platform-client'; try { const balance = await Token.getERC721TokenBalance('example-wallet', 'example-contract'); console.log(balance); } catch(err) { console.log(err); }
Returns
{Promise<ApiResponse<Balance>>}: A promise that resolves to the ERC721 token balance.Errors
{Error}: Throws an error if the request fails.Example Return
{ status: 'Success', data: { balance: 'example-balance' } }
2.7 Get ERC721 Token Owner
Fetches the owner of a specific ERC721 token.
Function Name
get_token_ownerArguments
contract_address (str): The ERC721 contract address. token_id (str): The token ID.Example Code
from crypto_com_developer_platform_client import Token owner = Token.get_token_owner('example-contract', 'example-token-id') print(owner)
Returns
The owner of the token.Errors
ValueError: If the Token class is not initialized with a Client instance.Example Return
{'status': 'Success', 'data': 'example-address'}
Function Name
getTokenOwnerArguments
{string} contractAddress: ERC721 contract address. {string} tokenId: Token ID.Example Code
import { Token } from '@crypto.com/developer-platform-client'; try { const owner = await Token.getTokenOwner('example-contract', 'example-token-id'); console.log(owner); } catch(err) { console.log(err); }
Returns
{Promise<ApiResponse<string>>}: A promise that resolves to the token owner information.Errors
{Error}: Throws an error if the request fails.Example Return
{ status: 'Success', data: 'example-owner' }
2.8 Get Token URI
Fetches the token URI of a specific ERC721 token.
Function Name
get_token_uriArguments
contract_address (str): The ERC721 contract address. token_id (str): The token ID.Example Code
from crypto_com_developer_platform_client import Token uri = Token.get_token_uri('example-contract', 'example-token-id') print(uri)
Returns
The token URI.Errors
ValueError: If the Token class is not initialized with a Client instance.Example Return
{'status': 'Success', 'data': 'example-token-uri'}
Function Name
getTokenURIArguments
{string} contractAddress: ERC721 contract address. {string} tokenId: Token ID.Example Code
import { Token } from '@crypto.com/developer-platform-client'; try { const uri = await Token.getTokenURI('example-contract', 'example-token-id'); console.log(uri); } catch(err) { console.log(err); }
Returns
{Promise<ApiResponse<string>>}: A promise that resolves to the token URI information.Errors
{Error}: Throws an error if the request fails.Example Return
{ status: 'Success', data: 'example-token-uri' }
2.9 Get ERC721 Metadata
Fetches metadata for a specific ERC721 contract.
Function Name
get_erc721_metadataArguments
contract_address (str): The ERC721 contract address.Example Code
from crypto_com_developer_platform_client import Token metadata = Token.get_erc721_metadata('example-contract') print(metadata)
Returns
The contract metadata.Errors
ValueError: If the Token class is not initialized with a Client instance.Example Return
{'status': 'Success', 'data': {'name': 'example-name', 'symbol': 'example-symbol'}}
Function Name
getERC721MetadataArguments
{string} contractAddress: ERC721 contract address.Example Code
import { Token } from '@crypto.com/developer-platform-client'; try { const metadata = await Token.getERC721Metadata('example-contract'); console.log(metadata); } catch(err) { console.log(err); }
Returns
{Promise<ApiResponse<TokenMetadata>>} A promise that resolves to the ERC721 contract metadata.Errors
{Error}: Throws an error if the request fails.Example Return
{ status: 'Success', data: { name: 'example-token-name', symbol: 'example-token-symbol' } }
2.10 Get ERC20 Metadata
Fetches metadata for a specific ERC20 contract.
Function Name
get_erc20_metadataArguments
contract_address (str): The ERC20 contract address.Example Code
from crypto_com_developer_platform_client import Token metadata = Token.get_erc20_metadata('example-contract') print(metadata)
Returns
The contract metadata.Errors
ValueError: If the Token class is not initialized with a Client instance.Example Return
{'status': 'Success', 'data': {'name': 'example-name', 'symbol': 'example-symbol', 'decimals': 'example-token-decimals'}}
Function Name
getERC20MetadataArguments
{string} contractAddress: ERC20 contract address.Example Code
import { Token } from '@crypto.com/developer-platform-client'; try { const metadata = await Token.getERC20Metadata('example-contract'); console.log(metadata); } catch(err) { console.log(err); }
Returns
{Promise<ApiResponse<TokenMetadata>>} A promise that resolves to the ERC20 contract metadata.Errors
{Error}: Throws an error if the request fails.Example Return
{ status: 'Success', data: { name: 'example-token-name', symbol: 'example-token-symbol', decimals: 'example-token-decimals' } }
Last updated
Was this helpful?