Skip to content

xmtplabs/xmtp-agent-examples / skills/handling-transactions

handling-transactions

Verified

Token transactions and wallet integration for XMTP agents. Use when sending USDC, creating transaction requests, or handling transaction confirmations. Triggers on USDC transfer, wallet calls, or transaction reference.

FileKindSize
SKILL.mdskill md3.9 KB
rules/balance-check.mdmarkdown2.0 KB
rules/receive-transaction-reference.mdmarkdown1.6 KB
rules/send-usdc-transfer.mdmarkdown1.5 KB

rules/balance-check.md

View on GitHub
---
title: Check USDC balance
impact: HIGH
tags: transactions, balance, usdc
---

## Check USDC balance

Use the SDK 2.2.0 `getERC20Balance` and `getERC20Decimals` to check token balances.

**Basic balance check:**

```typescript
import { getERC20Balance, getERC20Decimals, validHex } from "@xmtp/agent-sdk";
import { formatUnits } from "viem";
import { baseSepolia } from "viem/chains";

const CHAIN = baseSepolia;
const USDC_ADDRESS = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";

const balance = await getERC20Balance({
  chain: CHAIN,
  tokenAddress: USDC_ADDRESS,
  address: validHex(address),
});
const decimals = await getERC20Decimals({ chain: CHAIN, tokenAddress: USDC_ADDRESS });

await ctx.conversation.sendText(`Your balance: ${formatUnits(balance, decimals)} USDC`);
```

**In a command handler:**

```typescript
import {
  CommandRouter,
  getERC20Balance,
  getERC20Decimals,
  validHex,
} from "@xmtp/agent-sdk";
import { formatUnits } from "viem";

const router = new CommandRouter();

router.command("/balance", async (ctx) => {
  const agentAddress = agent.address;
  const senderAddress = await ctx.getSenderAddress();
  const decimals = await getERC20Decimals({ chain: CHAIN, tokenAddress: USDC_ADDRESS });

  const [agentBalance, senderBalance] = await Promise.all([
    getERC20Balance({ chain: CHAIN, tokenAddress: USDC_ADDRESS, address: validHex(agentAddress) }),
    getERC20Balance({ chain: CHAIN, tokenAddress: USDC_ADDRESS, address: validHex(senderAddress) }),
  ]);

  await ctx.conversation.sendText(
    `Agent balance: ${formatUnits(agentBalance, decimals)} USDC\n` +
      `Your balance: ${formatUnits(senderBalance, decimals)} USDC`,
  );
});
```

**Other ERC-20 tokens:**

Use the same `getERC20Balance` and `getERC20Decimals` with a different `tokenAddress` and chain.

**Requirements:**

- Smart contract wallet (SCW) required for transaction signing
- EOA wallets may see "Signature validation failed" error
- Get testnet USDC from [Circle Faucet](https://faucet.circle.com) or [Base Faucet](https://portal.cdp.coinbase.com/products/faucet)
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall