wagmi icon indicating copy to clipboard operation
wagmi copied to clipboard

bug: useBalance fails when token has bytes32 symbol

Open mwelche opened this issue 3 years ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Package Version

0.6.6

Current Behavior

useBalance fails on tokens that have their symbol as bytes32, unable to decode the bytes32 result of the function call. For example, useBalance with Maker (0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2) returns:

Failed to decode contract function result.

Config:
{
  "addressOrName": "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2",
  "contractInterface": "...",
  "functionName": "symbol",
  "chainId": 1
}

Details: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="symbol()", data="0x4d4b520000000000000000000000000000000000000000000000000000000000", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.7.0)

Expected Behavior

Would like to be able to use the useBalance hook and get a balance value back whether the other values are returned or not. symbol, in this case, doesn't seem like it should block the core function of the hook.

Steps To Reproduce

import { erc20ABI } from 'wagmi';
const chainId = 1;
const tokenAddress = '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2';
const { data: balance, error } = useBalance({
    addressOrName: accountAddress,
    chainId,
    token: tokenAddress,
  });

Link to Minimal Reproducible Example (CodeSandbox, StackBlitz, etc.)

No response

Anything else?

No response

mwelche avatar Sep 14 '22 05:09 mwelche

Is there an EIP that states symbol can be bytes32? Not really sure why this contract deviates from EIP-20's symbol type (a string).

I mean sure, we could probably support this case if it's a common one, but feels a bit strange since 0x4d4b520000000000000000000000000000000000000000000000000000000000 evaluates to MKR anyway lol.

jxom avatar Sep 14 '22 06:09 jxom

Hmm, they list it as a gotcha in their docs: https://docs.makerdao.com/smart-contract-modules/mkr-module#4.-gotchas-potential-source-of-user-error

Yeah, we may have to support it. Can take a look!

jxom avatar Sep 14 '22 06:09 jxom

Fixed in #993, but will close this issue when released.

jxom avatar Sep 27 '22 05:09 jxom

Published 0.6.8 that includes this fix!

jxom avatar Oct 06 '22 01:10 jxom

This issue has been locked since it has been closed for more than 14 days.

If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest wagmi version. If you have any other comments you can create a new discussion.

github-actions[bot] avatar Jan 16 '24 00:01 github-actions[bot]