feat(agent-sdk): add getNativeBalance helper in TransactionUtil - #4004
Open
mehmetkr-31 wants to merge 1 commit into
Open
mehmetkr-31 wants to merge 1 commit into
mehmetkr-31 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
getNativeBalancehelper andGetNativeBalanceOptionsto@xmtp/agent-sdkundersdks/js/agent-sdk/src/util/TransactionUtil.ts.While
TransactionUtilprovides 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'sclient.getBalance({ address }).Changes
TransactionUtil.ts: AddedGetNativeBalanceOptionstype andgetNativeBalance(options: GetNativeBalanceOptions): Promise<bigint>implementation using viemcreatePublicClient.TransactionUtil.test.ts: Added unit test verifying native balance retrieval with mocked viemgetBalance.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)Note
Add
getNativeBalancehelper toTransactionUtilin the agent SDKAdds an exported
getNativeBalanceasync function toTransactionUtil.tsthat queries the native token balance (in wei) for a given address using viem'sgetBalance. It accepts aGetNativeBalanceOptionstype withchain,address, and an optionaltransport(defaults tohttp()).Macroscope summarized 00fe180.