Skip to content

fix: read ERC-20 token details on chains without multicall3 - #1535

Open
selimaytac wants to merge 1 commit into
coinbase:mainfrom
selimaytac:fix/erc20-token-details-without-multicall3
Open

selimaytac wants to merge 1 commit into
coinbase:mainfrom
selimaytac:fix/erc20-token-details-without-multicall3

Conversation

@selimaytac

Copy link
Copy Markdown

Description

Closes #1533.

getTokenDetails() (erc20) reads name, decimals and balanceOf with publicClient.multicall(). On chains whose viem definition has no contracts.multicall3 (viem's foundry chain for a local Anvil, custom chains), viem throws ChainDoesNotSupportContract before sending any request, the catch turns it into null, and get_balance, transfer, approve and get_allowance always answer "Could not fetch token details".

With this change, when multicall() throws ChainDoesNotSupportContract, the three values are read with plain readContract calls instead. Chains with Multicall3 keep the single multicall request, and any other error is handled as before (null). The error is matched by its name rather than instanceof, so it also works when the public client comes from another viem copy.

Scope: this PR only adds the fallback. Surfacing the underlying error in the action output, the second point in the issue, changes what getTokenDetails returns, and the erc20 actions and baseAccount depend on that, so I left it for a follow-up if you want it. The other helpers that multicall (cdp/swapUtils.ts, zeroX/utils.ts, truemarkets) only run on networks those services support, which all have Multicall3, so they are unchanged.

Tests

Unit tests (erc20ActionProvider.test.ts, Get Balance Action):

  • new: on ChainDoesNotSupportContract the token is read with three readContract calls and the balance is returned (fails without the fix, passes with it)
  • new: if a plain read fails, the action still reports "Could not fetch token details"
  • existing: other multicall errors do not fall back (now also asserts readContract is not called)
  • jest src/action-providers/erc20 src/action-providers/baseAccount: 52 passed; eslint, prettier and tsc --noEmit clean

No chatbot run; instead the repro from #1533 against a local Anvil, with the built package. Note: the repro in the issue builds ViemWalletProvider without rpcUrl, so its public client uses the chain's default RPC (port 8545) instead of the Anvil on 18545. That does not change the diagnosis (the multicall error is thrown before any request), but the fallback needs a reachable RPC, so for this run the provider is built as:

const walletProvider = new ViemWalletProvider(
  createWalletClient({ account, chain: foundry, transport: http(rpc) }),
  { rpcUrl: rpc },
);
Network: local Anvil (viem foundry chain, no multicall3)

main:
get_balance -> Error: Could not fetch token details for 0x00000000000000000000000000000000000000aa

this branch:
get_balance -> Balance of TEST (0x00000000000000000000000000000000000000aa) at address 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 is 1000
transfer    -> Transferred 1 of TEST (0x00000000000000000000000000000000000000aa) to 0x70997970C51812dc3A010C7d01b50e0d17dc79C8.
Transaction hash for the transfer: 0x9d7c79cf3c456afe1759b5bca6a5ea5f64886af1018481d53257a1f235436d1a
approve     -> Approved 1 TEST (0x00000000000000000000000000000000000000aa) for spender 0x70997970C51812dc3A010C7d01b50e0d17dc79C8.
Transaction hash: 0xa31bb6124992c75929df3027151d30560c62440162137308fa62c3e5bf663377

Checklist

  • Added documentation to all relevant README.md files (not applicable: no API or behaviour to document)
  • Added a changelog entry

@cb-heimdall

Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@github-actions github-actions Bot added documentation Improvements or additions to documentation action provider New action provider typescript labels Oct 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action provider New action provider documentation Improvements or additions to documentation typescript

2 participants