ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.82k stars 1.81k forks source link

AnkrProvider: Fantom not supported ? #3726

Open Pandazaur opened 1 year ago

Pandazaur commented 1 year ago

Hello, I'm trying to use the AnkrProvider with "Fantom Opera" network but unfortunately I can't do it because the network is not supported. I checked ethers/src.ts/providers/provider-ankr.ts and no reference to Fantom is present.

Ankr supports Fantom in their documentation. How can I use the Ankr RPC with Fantom and ethers.js ?

I tried something which doesn't work:

const provider = new ethers.WebSocketProvider(
        'wss://rpc.ankr.com/fantom/ws/<API_KEY>',
        BLOCKCHAIN_NETWORK_ID.FANTOM
    )
provider.getBalance('<public_addr>')

It gives me this error:

/Users/alexandreborel/Programmation/arbitrage/node_modules/.pnpm/ws@8.5.0/node_modules/ws/lib/websocket.js:852
      abortHandshake(
      ^
Error: Unexpected server response: 200
    at ClientRequest.<anonymous> (/Users/alexandreborel/Programmation/arbitrage/node_modules/.pnpm/ws@8.5.0/node_modules/ws/lib/websocket.js:852:7)
    at ClientRequest.emit (events.js:315:20)
    at ClientRequest.EventEmitter.emit (domain.js:467:12)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:641:27)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17)
    at TLSSocket.socketOnData (_http_client.js:509:22)
    at TLSSocket.emit (events.js:315:20)
    at TLSSocket.EventEmitter.emit (domain.js:467:12)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)

I'm using ethers.js v6. Any idea how to resolve this issue ? Thanks

ricmoo commented 1 year ago

You need to use the JsonRpcProvider and pass in the necessary parameters, and can optimize it by passing { staticNetwork: YourNetwokInfo }. I'll include more details on this in the docs. :)