Skip to content

feat(agent-sdk): add getNativeBalance helper in TransactionUtil - #4004

Open
mehmetkr-31 wants to merge 1 commit into
xmtp:mainfrom
mehmetkr-31:feat/agent-sdk-get-native-balance
Open

mehmetkr-31 wants to merge 1 commit into
xmtp:mainfrom
mehmetkr-31:feat/agent-sdk-get-native-balance

Conversation

@mehmetkr-31

@mehmetkr-31 mehmetkr-31 commented Aug 16, 2026

Copy link
Copy Markdown

Summary

Adds getNativeBalance helper and GetNativeBalanceOptions to @xmtp/agent-sdk under sdks/js/agent-sdk/src/util/TransactionUtil.ts.

While TransactionUtil provides both ERC-20 (createERC20TransferCalls) and native token transfer helpers (createNativeTransferCalls), it previously only provided balance querying utilities for ERC-20 tokens (getERC20Balance, getERC20Decimals). This addition completes the API symmetry by allowing agents to query native token (ETH/MATIC) balances directly via viem's client.getBalance({ address }).

Changes

  • TransactionUtil.ts: Added GetNativeBalanceOptions type and getNativeBalance(options: GetNativeBalanceOptions): Promise<bigint> implementation using viem createPublicClient.
  • TransactionUtil.test.ts: Added unit test verifying native balance retrieval with mocked viem getBalance.

Verification

  • yarn workspace @xmtp/agent-sdk run vitest run src/util/TransactionUtil.test.ts (11/11 tests pass)
  • npx eslint agent-sdk/src/util/TransactionUtil.ts agent-sdk/src/util/TransactionUtil.test.ts (Clean)
  • GPG signed commit.

Note

Add getNativeBalance helper to TransactionUtil in the agent SDK

Adds an exported getNativeBalance async function to TransactionUtil.ts that queries the native token balance (in wei) for a given address using viem's getBalance. It accepts a GetNativeBalanceOptions type with chain, address, and an optional transport (defaults to http()).

Macroscope summarized 00fe180.

@mehmetkr-31
mehmetkr-31 requested a review from a team as a code owner August 16, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant