Skip to content

Smart Transfer Action

This tool allows the agent to transfer native assets (like ETH or MATIC) or ERC-20 tokens (like USDC) to an address.

Under the hood, this action constructs an ERC-4337 UserOperation. The transaction is submitted to the 0xGasless Bundler and paid for by the Paymaster.

When the user asks the agent to send tokens, the LLM will generate a call matching this schema.

ArgumentTypeDescription
tostringThe recipient’s EVM address, or a supported ENS/BNS name.
amountstringThe amount to send, in human-readable units (e.g., "1.5").
tokenAddressstringOptional. The contract address of the ERC-20 token to send. If omitted, the native chain token is transferred.
  1. Resolution: If to is a name like vitalik.eth, the action queries an RPC to resolve the address.
  2. Decimals: Native transfers always assume 18 decimals. If tokenAddress is provided, the action executes an on-chain decimals() call to determine how to convert the human-readable string into wei.
  3. Execution:
    • Native: Encodes a transaction to the recipient with value: amountInWei and empty data.
    • ERC-20: Encodes a transaction to tokenAddress with value: 0 and data: transfer(to, amountInWei).

If you don’t want to use an LLM, you can directly invoke the action from code using the AgentKit framework:

import { AgentKit, SmartTransferAction } from "@0xgasless/agent-sdk";
const agentKit = new AgentKit({ apiKey: "YOUR_API_KEY" });
const action = new SmartTransferAction();
const result = await action.invoke(agentKit, {
to: "0xRecipientAddress",
amount: "10.5",
tokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
});
console.log(result);
// "Successfully transferred 10.5 USDC to 0xRecipientAddress. Transaction hash: 0x..."

The Prompt passed to the LLM handles edge cases explicitly. It tells the agent:

  • “If the user asks to send ‘USDC’, you must look up the USDC token address and pass it in tokenAddress. Do not send the string ‘USDC’.”
  • “Do not provide the amount scaled by decimals. Always provide the raw number.”
  • The agent cannot transfer tokens it does not have. Ensure the smart account is funded before asking the agent to act.
  • The action waits for the UserOperation to be mined into a block before returning a success string. This can take several seconds depending on network congestion.