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>"
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>"
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>"
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>"
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"
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>"
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)
Last updated
Was this helpful?