Crypto.com AI Agent SDK
  • Getting Started
    • Introduction
    • Quick Start Guide: Simulation Entry Point
  • Core Concepts Overview
    • Plugins
    • Tools
    • Blockchain Functions
      • Wallet Management
      • Token Interaction
      • Transaction Queries
      • Block Information
      • Contract Operations
      • CronosID Operations
      • Defi Operations
      • Crypto.com Exchange
    • Built-in Telegram Feature
    • Advanced Usage: Custom Instructions
    • Dynamic AI Model Manager
  • Crypto.com On-Chain Developer Platform
    • Developer Platform API Methods
  • On-Chain Functions and Examples
    • AI Agent Chatbot
    • "Magic Link" Signer
  • Resources for Developers
Powered by GitBook
On this page

Was this helpful?

  1. Core Concepts Overview
  2. Blockchain Functions

Token Interaction

The AI Agent SDK offers powerful token interaction capabilities on the Cronos blockchain. It supports retrieving token balances for both native tokens and ERC20 tokens, performing token transfers, as well as wrapping and swapping tokens.

This comprehensive feature set makes it easy for developers to build AI agents that smoothly interact with tokens.

2.1 Get native balance

Query the native token balance for the specified blockchain address using the Crypto.com developer platform.

  • Arguments

    address (str): The blockchain address to query.
  • Example Query

    "Get native balance of <example-address>"
  • Returns

    str: A formatted string containing the native token balance for the address.
  • Example Response

    The native balance for address <example-address> is <example-amount> CRO (CRO being the native token).

Example Code

from crypto_com_agent_client import Agent

agent = Agent.init(
    llm_config={
        "provider": "OpenAI",
        "model": "gpt-4",
        "provider-api-key": "sk-proj-example-key",
        "temperature": "float-controlling-output-randomness",
    },
    blockchain_config={
         "chainId": "chain-id",
         "explorer-api-key": "your-api-key",
         "private-key": "your-private-key",
         "sso-wallet-url": "your-sso-wallet-url",
    },
)
response = agent.interact("Get native balance of <example-address>")
print(response)

2.2 Get ERC20 Token Balance

Query the ERC20 token balance for the specified blockchain address and ERC20 contract address.

  • Arguments

    address (str): The blockchain address to query.
    contract_address (str): The contract address of the ERC20 token.
  • Example Query

    "Get ERC20 balance of <example-address> in contract <example-contract>"
  • Returns

    str: A formatted string containing the ERC20 token balance for the address.
  • Example Response

    The ERC20 balance for address <example-address> in the contract <example-contract> is <example-amount> tokens.

Example Code

from crypto_com_agent_client import Agent

agent = Agent.init(
    llm_config={
        "provider": "OpenAI",
        "model": "gpt-4",
        "provider-api-key": "sk-proj-example-key",
        "temperature": "float-controlling-output-randomness",
    },
    blockchain_config={
         "chainId": "chain-id",
         "explorer-api-key": "your-api-key",
         "private-key": "your-private-key",
         "sso-wallet-url": "your-sso-wallet-url",
    },
)
response = agent.interact("Get ERC20 balance of <example-address> in contract <example-contract>")
print(response)

2.3 Transfer native token

Transfer native tokens (cro, CRO, tcro, tCRO, zkcro, zkCRO, zktcro, zkTCRO) to a specified address using the Crypto.com developer platform.

  • Arguments

    state (dict): The current state of the workflow.
    to (str): The recipient's blockchain address. 
    amount (float): The amount of native tokens to transfer.
  • Example Query

    "Transfer <example-amount> CRO to <example-to>"
  • Returns

    str: A formatted string confirming the success of the token transfer.
  • Example Response

    The transfer of <example-amount> CRO to <example-to> was successful. 
    You can view the transaction details [here](<example-transaction-explorer-link>).

Example Code

from crypto_com_agent_client import Agent

agent = Agent.init(
    llm_config={
        "provider": "OpenAI",
        "model": "gpt-4",
        "provider-api-key": "sk-proj-example-key",
        "temperature": "float-controlling-output-randomness",
    },
    blockchain_config={
         "chainId": "chain-id",
         "explorer-api-key": "your-api-key",
         "private-key": "your-private-key",
         "sso-wallet-url": "your-sso-wallet-url",
    },
)
response = agent.interact("Transfer <example-amount> CRO to <example-to>")
print(response)

2.4 Transfer ERC20 token

Transfer ERC20 tokens to a specified address.

  • Arguments

    state (dict): The current state of the workflow.
    to (str): The recipient's blockchain address. 
    amount (float): The amount of tokens to transfer. 
    token_symbol_or_address (str): The ERC20 token symbol or contract address.
  • Example Query

    "Transfer <exmaple-amount> to <example-to> of contract <example-token>"
  • Returns

    str: A formatted string confirming the success of the token transfer.
  • Example Response

    The transfer of <exmaple-amount> to <example-to> of contract <example-token> was successful. 
    
    You can view the transaction details [here](<example-transaction-explorer-link>).

Example Code

from crypto_com_agent_client import Agent

agent = Agent.init(
    llm_config={
        "provider": "OpenAI",
        "model": "gpt-4",
        "provider-api-key": "sk-proj-example-key",
        "temperature": "float-controlling-output-randomness",
    },
    blockchain_config={
         "chainId": "chain-id",
         "explorer-api-key": "your-api-key",
         "private-key": "your-private-key",
         "sso-wallet-url": "your-sso-wallet-url",
    },
)
response = agent.interact("Transfer <exmaple-amount> to <example-to> of contract <example-token>")
print(response)

2.5 Wrap token

Wrap native tokens into wrapped tokens using the Crypto.com developer platform.

  • Arguments

    state (dict): The current state of the workflow.
    amount (float): The amount of native tokens to wrap.
  • Example Query

    "Wrap <example-amount> CRO token"
  • Returns

    str: A formatted string confirming the success of the wrapping operation.
  • Example Response

    The CRO token wrapping was successful. 
    - Transaction Hash: <example-transaction-hash>
    - Transaction Link: [View Transaction](<example-transaction-explorer-link>)

Example Code

from crypto_com_agent_client import Agent

agent = Agent.init(
    llm_config={
        "provider": "OpenAI",
        "model": "gpt-4",
        "provider-api-key": "sk-proj-example-key",
        "temperature": "float-controlling-output-randomness",
    },
    blockchain_config={
         "chainId": "chain-id",
         "explorer-api-key": "your-api-key",
         "private-key": "your-private-key",
         "sso-wallet-url": "your-sso-wallet-url",
    },
)
response = agent.interact("Wrap <example-amount> CRO token")
print(response)

2.6 Swap token

Swap tokens between two different tokens.

  • Arguments

    state: The current state of the workflow.
    from_token_symbol_or_address (str): The symbol or contract address of the token to swap from.
    to_token_symbol_or_address (str): The symbol or contract address of the token to swap to.
    amount (float): The amount of tokens to swap.
  • Example Query

    "Swap <example-amount> <example-from-token> for <example-to-token>"
  • Returns

    str: A formatted string confirming the success of the token swap.
  • Example Response

    The token swap of <example-amount> <example-from-token> for <example-to-token> was successful. 
    
    - Transaction Hash: [<example-transaction-hash>](<example-explorer-link>) 
    
    You can view the transaction details by clicking on the link.

Example Code

from crypto_com_agent_client import Agent

agent = Agent.init(
    llm_config={
        "provider": "OpenAI",
        "model": "gpt-4",
        "provider-api-key": "sk-proj-example-key",
        "temperature": "float-controlling-output-randomness",
    },
    blockchain_config={
         "chainId": "chain-id",
         "explorer-api-key": "your-api-key",
         "private-key": "your-private-key",
         "sso-wallet-url": "your-sso-wallet-url",
    },
)
response = agent.interact("Swap <example-amount> <example-from-token> for <example-to-token>")
print(response)
PreviousWallet ManagementNextTransaction Queries

Last updated 1 day ago

Was this helpful?