wevm / viem

TypeScript Interface for Ethereum
https://viem.sh
Other
2.52k stars 815 forks source link

bug: publicClient doesn't work for SKALE networks #910

Closed dmytrotkk closed 1 year ago

dmytrotkk commented 1 year ago

Is there an existing issue for this?

Package Version

1.3.0

Current Behavior

With the current implementation, all JSON RPC calls don't work in case of using publicClient:

import {
    http,
    createPublicClient
} from 'viem';
import { skaleCalypso } from 'wagmi/chains';

const client = createPublicClient({
    chain: skaleCalypso,
    transport: http()
});

...

await client1.getBlockNumber(); // throws an error: Uncaught (in promise) TypeError: Cannot convert undefined to a BigInt

The root cause of this issue is a combination of 2 factors:

  1. SKALE Chains doesn't add application/json in Content-Type header.
  2. viem doesn't handle this case correctly in the rpc module.

Without application/json it goes to this if clause, and then passed (in string format, without being parsed) here - both error and result are undefined because of this.

Expected Behavior

Correct behaviour when using SKALE Chains, since they are a part of wagmi/chains module.

Steps To Reproduce

  1. Import any SKALE Chain from wagmi/chains (e.g. skaleCalypso)
  2. Init publicClient using http as a transport
  3. Make any call

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

https://stackblitz.com/edit/viem-getting-started-po5zk3?file=index.ts

Anything else?

No response

jxom commented 1 year ago

That’s a bit annoying. I’d say viem’s implementation is technically correct as without an application/json header, the response is essentially raw text (even though it might be represented as json). Wonder what it would take to fix this on Skale’s side.

jxom commented 1 year ago

Let's track this issue here: https://github.com/skalenetwork/skaled/issues/1619.

github-actions[bot] commented 5 months ago

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 Viem version. If you have any questions or comments you can create a new discussion thread.