shazow / whatsabi

Extract the ABI (and resolve proxies, and get other metadata) from Ethereum bytecode, even without source code.
https://shazow.github.io/whatsabi/
MIT License
1.06k stars 74 forks source link

autoload: Compatible provider behaving incorrectly for latest viem version #93

Closed Plopmenz closed 4 months ago

Plopmenz commented 4 months ago

Calling whatsabi.autoload(< address >, {provider: < viem public client >}) will throw an error when using the latest version of viem. getBytecode is now deprecated and viem is also using getCode. This makes CompatibleProvider classify it as Ethers5Provider, resulting in none of the function arguments to be correctly passed to the viem provider. Hence the call to retrieve the (byte)code of the provided address will throw an RPC error, due to address being null (the .address property is requested and equals to null, as viem expects an object as input, not a string).

A current workaround to make this getCode call succeed until whatsabi is updated would be to use an extension of string as address passed to autoload:

class AddressString extends String {
  address: Address;

  constructor(value: Address) {
    super(value);
    this.address = value;
  }
}

This would need to be extended with arguments of any other provider calls in case they are desired to succeed.

shazow commented 4 months ago

Hmm good to know! I haven't been keeping up with the latest viem changes, will need to investigate.

shazow commented 4 months ago

Should be fixed in the latest release v0.13.1, can you please confirm that it's working for you now? Thanks for the bug report!

Plopmenz commented 4 months ago

Thank you for the fast resolution!

Confirmed it is working now, at least within the scope of my project. Happy I could contribute!