# 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](/crypto.com-ai-agent-sdk/core-concepts-overview/blockchain-functions/token-interaction.md).

#### 2.1 Get Native Token Balance

Fetches the native token balance of a specific wallet address.

{% tabs %}
{% tab title="Python" %}
Function Name

```python
get_native_balance
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```python
  address (str): The address to get the balance for (CronosIds with the `.cro` suffix are supported, e.g. `xyz.cro`)
  ```
* Example Code

  ```python
  from crypto_com_developer_platform_client import Token

  balance = Token.get_native_balance('example-wallet')
  print(balance)
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```python
  The balance of the native token.
  ```
* Errors

  ```python
  ValueError: If the Token class is not initialized with a Client instance.
  ```
* Example Return

  ```python
  {'status': 'Success', 'data': {'balance': 'example-balance'}}
  ```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="TypeScript" %}
Function Name

```typescript
getNativeTokenBalance
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```typescript
  {string} address: The wallet address (or CronosId `.cro`) to check.
  ```
* Example Code

  ```typescript
  import { Token } from '@crypto.com/developer-platform-client';

  try {
    const balance = await Token.getNativeTokenBalance('example-wallet');
    console.log(balance);
  }
  catch(err) {
    console.log(err);
  }
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```typescript
  {Promise<ApiResponse<Balance>>}: A promise that resolves to the native token balance.
  ```
* Errors

  ```typescript
  {Error}: Throws an error if the request fails.
  ```
* Example Return

  ```typescript
  { status: 'Success', data: { balance: 'example-balance' } }
  ```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

#### 2.2 Get ERC20 Token Balance

Fetches the ERC20 token balance of a wallet for a given ERC20 contract.

{% tabs %}
{% tab title="Python" %}
Function Name

```python
get_erc20_balance
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```python
  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

  ```python
  from crypto_com_developer_platform_client import Token

  balance = Token.get_erc20_balance('example-wallet', 'example-contract', 'latest')
  print(balance)
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```python
  The balance of the ERC20 token.
  ```
* Errors

  ```python
  ValueError: If the Token class is not initialized with a Client instance.
  ```
* Example Return

  ```python
  {'status': 'Success', 'data': {'balance': 'example-balance'}}
  ```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="TypeScript" %}
Function Name

```typescript
getERC20TokenBalance
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```typescript
  {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

  ```typescript
  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);
  }
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```typescript
  {Promise<ApiResponse<TokenBalance>>}: A promise that resolves to the ERC20 token balance.
  ```
* Errors

  ```typescript
  {Error}: Throws an error if the request fails.
  ```
* Example Return

  ```typescript
  { status: 'Success', data: { balance: 'example-balance' } }
  ```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

#### 2.3 Transfer Token

Transfers native or ERC20 tokens.

{% tabs %}
{% tab title="Python" %}
Function Name

```python
transfer_token
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```python
  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

  ```python
  from crypto_com_developer_platform_client import Token

  tx = Token.transfer_token('example-recipient', example-number)
  print(tx)
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```python
  The transaction hash.
  ```
* Errors

  ```python
  ValueError: If the Token class is not initialized with a Client instance.
  ```
* Example Return

  ```python
  {'status': 'Success', 'data': {'magicLink': 'example-magic-link'}}
  ```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="TypeScript" %}
Function Name

```typescript
transfer
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```typescript
  {object} payload: Transfer parameters.
  {string} payload.to: Recipient address.
  {number} payload.amount: Amount to transfer.
  {string} [payload.contractAddress]: ERC20 contract address (optional)
  ```
* Example Code

  ```typescript
  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);
  }
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```typescript
  {Promise<ApiResponse<MagicLinkData>>}: A promise that resolves to the transaction result.
  ```
* Errors

  ```typescript
  {Error}: Throws an error if the request fails.
  ```
* Example Return

  ```typescript
  {
    status: 'Success',
    data: {
      magicLink: 'example-magic-link'
    }
  }
  ```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

#### 2.4 Wrap Token

Wrap tokens.

{% tabs %}
{% tab title="Python" %}
Function Name

```python
wrap_token
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```python
  amount (float): The amount of the token to wrap.
  ```
* Example Code

  ```python
  from crypto_com_developer_platform_client import Token

  tx = Token.wrap_token(example-amount)
  print(tx)
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```python
  The transaction hash.
  ```
* Errors

  ```python
  ValueError: If the Token class is not initialized with a Client instance.
  ```
* Example Return

  ```python
  {'status': 'Success', 'data': {'magicLink': 'example-magic-link'}}
  ```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="TypeScript" %}
Function Name

```typescript
wrap
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```typescript
  {object} payload: Wrap parameters.
  {number} payload.amount: Amount to wrap.
  ```
* Example Code

  ```typescript
  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);
  }
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```typescript
  {Promise<ApiResponse<MagicLinkData>>}: A promise that resolves to the wrap transaction result.
  ```
* Errors

  ```typescript
  {Error}: Throws an error if the request fails.
  ```
* Example Return

  ```typescript
  {
    status: 'Success',
    data: {
      magicLink: 'example-magic-link'
    }
  }
  ```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

#### 2.5 Swap Token

Swap tokens.

{% tabs %}
{% tab title="Python" %}
Function Name

```python
swap_token
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```python
  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

  ```python
  from crypto_com_developer_platform_client import Token

  tx = Token.swap_token('example-from', 'example-to', 'example-amount')
  print(tx)
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```python
  The transaction hash.
  ```
* Errors

  ```python
  ValueError: If the Token class is not initialized with a Client instance.
  ```
* Example Return

  ```python
  {'status': 'Success', 'data': {'magicLink': 'example-magic-link'}}
  ```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="TypeScript" %}
Function Name

```typescript
swap
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```typescript
  {object} payload: Swap parameters.
  {string} payload.fromContractAddress: Token being swapped.
  {string} payload.toContractAddress: Token to receive.
  {number} payload.amount: Amount to swap.
  ```
* Example Code

  ```typescript
  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);
  }
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```typescript
  {Promise<ApiResponse<MagicLinkData>>}: A promise that resolves to the swap transaction result.
  ```
* Errors

  ```typescript
  {Error}: Throws an error if the request fails.
  ```
* Example Return

  ```typescript
  {
    status: 'Success',
    data: {
      magicLink: 'example-magic-link'
    }
  }
  ```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

#### 2.6 Get ERC721 Token Balance

Fetches the ERC721 token balance for a wallet and contract.

{% tabs %}
{% tab title="Python" %}
Function Name

```python
get_erc721_balance
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```python
  wallet_address (str): The address to get the balance for.
  contract_address (str): The ERC721 contract address.
  ```
* Example Code

  ```python
  from crypto_com_developer_platform_client import Token

  balance = Token.get_erc721_balance('example-wallet','example-contract')
  print(balance)
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```python
  The ERC721 token balance.
  ```
* Errors

  ```python
  ValueError: If the Token class is not initialized with a Client instance.
  ```
* Example Return

  ```python
  {'status': 'Success', 'data': {'balance': 'example-balance'}}
  ```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="TypeScript" %}
Function Name

```typescript
getERC721TokenBalance
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```typescript
  {string} walletAddress: Wallet address to check.
  {string} contractAddress: ERC721 contract address.
  ```
* Example Code

  ```typescript
  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);
  }
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```typescript
  {Promise<ApiResponse<Balance>>}: A promise that resolves to the ERC721 token balance.
  ```
* Errors

  ```typescript
  {Error}: Throws an error if the request fails.
  ```
* Example Return

  ```typescript
  { status: 'Success', data: { balance: 'example-balance' } }
  ```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

#### 2.7 Get ERC721 Token Owner

Fetches the owner of a specific ERC721 token.

{% tabs %}
{% tab title="Python" %}
Function Name

```python
get_token_owner
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```python
  contract_address (str): The ERC721 contract address.
  token_id (str): The token ID.
  ```
* Example Code

  ```python
  from crypto_com_developer_platform_client import Token

  owner = Token.get_token_owner('example-contract', 'example-token-id')
  print(owner)
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```python
  The owner of the token.
  ```
* Errors

  ```python
  ValueError: If the Token class is not initialized with a Client instance.
  ```
* Example Return

  ```python
  {'status': 'Success', 'data': 'example-address'}
  ```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="TypeScript" %}
Function Name

```typescript
getTokenOwner
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```typescript
  {string} contractAddress: ERC721 contract address.
  {string} tokenId: Token ID.
  ```
* Example Code

  ```typescript
  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);
  }
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```typescript
  {Promise<ApiResponse<string>>}: A promise that resolves to the token owner information.
  ```
* Errors

  ```typescript
  {Error}: Throws an error if the request fails.
  ```
* Example Return

  ```typescript
  {
    status: 'Success',
    data: 'example-owner'
  }
  ```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

#### 2.8 Get Token URI

Fetches the token URI of a specific ERC721 token.

{% tabs %}
{% tab title="Python" %}
Function Name

```python
get_token_uri
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```python
  contract_address (str): The ERC721 contract address.
  token_id (str): The token ID.
  ```
* Example Code

  ```python
  from crypto_com_developer_platform_client import Token

  uri = Token.get_token_uri('example-contract', 'example-token-id')
  print(uri)
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```python
  The token URI.
  ```
* Errors

  ```python
  ValueError: If the Token class is not initialized with a Client instance.
  ```
* Example Return

  ```python
  {'status': 'Success', 'data': 'example-token-uri'}
  ```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="TypeScript" %}
Function Name

```typescript
getTokenURI
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```typescript
  {string} contractAddress: ERC721 contract address.
  {string} tokenId: Token ID.
  ```
* Example Code

  ```typescript
  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);
  }
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```typescript
  {Promise<ApiResponse<string>>}: A promise that resolves to the token URI information.
  ```
* Errors

  ```typescript
  {Error}: Throws an error if the request fails.
  ```
* Example Return

  ```typescript
  {
    status: 'Success',
    data: 'example-token-uri'
  }
  ```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

#### 2.9 Get ERC721 Metadata

Fetches metadata for a specific ERC721 contract.

{% tabs %}
{% tab title="Python" %}
Function Name

```python
get_erc721_metadata
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```python
  contract_address (str): The ERC721 contract address.
  ```
* Example Code

  ```python
  from crypto_com_developer_platform_client import Token

  metadata = Token.get_erc721_metadata('example-contract')
  print(metadata)
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```python
  The contract metadata.
  ```
* Errors

  ```python
  ValueError: If the Token class is not initialized with a Client instance.
  ```
* Example Return

  ```python
  {'status': 'Success', 'data': {'name': 'example-name', 'symbol': 'example-symbol'}}
  ```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="TypeScript" %}
Function Name

```typescript
getERC721Metadata
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```typescript
  {string} contractAddress: ERC721 contract address.
  ```
* Example Code

  ```typescript
  import { Token } from '@crypto.com/developer-platform-client';

  try {
    const metadata = await Token.getERC721Metadata('example-contract');
    console.log(metadata);
  }
  catch(err) {
    console.log(err);
  }
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```typescript
  {Promise<ApiResponse<TokenMetadata>>} A promise that resolves to the ERC721 contract metadata.
  ```
* Errors

  ```typescript
  {Error}: Throws an error if the request fails.
  ```
* Example Return

  ```typescript
  { status: 'Success', data: { name: 'example-token-name', symbol: 'example-token-symbol' } }
  ```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

#### 2.10 Get ERC20 Metadata

Fetches metadata for a specific ERC20 contract.

{% tabs %}
{% tab title="Python" %}
Function Name

```python
get_erc20_metadata
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```python
  contract_address (str): The ERC20 contract address.
  ```
* Example Code

  ```python
  from crypto_com_developer_platform_client import Token

  metadata = Token.get_erc20_metadata('example-contract')
  print(metadata)
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```python
  The contract metadata.
  ```
* Errors

  ```python
  ValueError: If the Token class is not initialized with a Client instance.
  ```
* Example Return

  ```python
  {'status': 'Success', 'data': {'name': 'example-name', 'symbol': 'example-symbol', 'decimals': 'example-token-decimals'}}
  ```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="TypeScript" %}
Function Name

```typescript
getERC20Metadata
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```typescript
  {string} contractAddress: ERC20 contract address.
  ```
* Example Code

  ```typescript
  import { Token } from '@crypto.com/developer-platform-client';

  try {
    const metadata = await Token.getERC20Metadata('example-contract');
    console.log(metadata);
  }
  catch(err) {
    console.log(err);
  }
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```typescript
  {Promise<ApiResponse<TokenMetadata>>} A promise that resolves to the ERC20 contract metadata.
  ```
* Errors

  ```typescript
  {Error}: Throws an error if the request fails.
  ```
* Example Return

  ```typescript
  {
    status: 'Success',
    data: { name: 'example-token-name', symbol: 'example-token-symbol', decimals: 'example-token-decimals' }
  }
  ```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ai-agent-sdk-docs.crypto.com/crypto.com-developer-platform/on-chain-developer-platform-client-sdk/token-module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
