ethers-io / ethers.js

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

Fallbacks for Polygon/Mumbai gas stations #4320

Open vaivanov opened 1 year ago

vaivanov commented 1 year ago

Ethers Version

6.7.1

Search Terms

gas, gas station, EIP-1559

Describe the Problem

When I'm trying to call getFeeData on Polygon Mumbai network and gas station doesn't work well at the moment (in example, https://gasstation-testnet.polygon.technology/v2 returns 503 error), I'm getting error "Error: error encountered with polygon gas station". I suggest to implement fallback for this case, or make getGasStationPlugin connection configurable for Polygon based networks.

Code Snippet

import { JsonRpcProvider } from 'ethers'

const provider = new JsonRpcProvider('https://rpc.ankr.com/polygon_mumbai');

await provider.getFeeData();

Contract ABI

No response

Errors

Error: error encountered with polygon gas station ("https://gasstation-testnet.polygon.technology/v2") (request={  }, response={  }, error={ "code": "UNSUPPORTED_OPERATION", "info": { "response": {  } }, "operation": "bodyJson" }, code=SERVER_ERROR, version=6.7.1)
    at makeError (/app/node_modules/ethers/lib.commonjs/utils/errors.js:125:21)
    at assert (/app/node_modules/ethers/lib.commonjs/utils/errors.js:142:15)
    at FetchUrlFeeDataNetworkPlugin.<anonymous> (/app/node_modules/ethers/lib.commonjs/providers/network.js:290:35)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async JsonRpcProvider.getFeeData (/app/node_modules/ethers/lib.commonjs/providers/abstract-provider.js:609:29)
....

Environment

Other (please specify)

Environment (Other)

Polygon, Mumbai

mohitvdx commented 1 year ago

https://gasstation-testnet.polygon.technology/v2 works well now. What fallback do you want to be added?

vaivanov commented 1 year ago

Hello,

This API serves as a centralized resource which may experience intermittent downtime. Upon reviewing my backend logs, I observed that the success rate was only 97% at the time of opening this issue. It's worth noting that the GasStation API shouldn't be a requirement for transaction execution. We can obtain information about the expected maxPriorityFeePerGas and maxFeePerGas directly from the network, just as it functions on other chains.

However, a challenge arises when the gas station encounters downtime or delivers rate-limited responses, preventing me from accurately estimating the gas required for transactions.

I propose the following solutions:

Your understanding and consideration of these suggestions would be greatly appreciated.

Thank you.

victoryeo commented 1 year ago

We are using etherjsv6. We are also seeing the same gas station error on polygon network. This is a showstopper and needs to be fixed.

vaivanov commented 8 months ago

image

Error: error encountered with polygon gas station ("https://gasstation.polygon.technology/v2") (request={ }, response={ }, error={ "code": "UNSUPPORTED_OPERATION", "info": { "response": { } }, "operation": "bodyJson" }, code=SERVER_ERROR, version=6.7.1)

ricmoo commented 8 months ago

If the Polygon Gas Station is down, there isn’t really a reliable way to get the gas price other than running your own gas station of finding another public gas station.

ricmoo commented 8 months ago

(if you upgrade to the latest version, the error will contain more info on the error from the server)

MatevzKlancar commented 4 months ago

why does this api always return the same values for different variables? safeLow, standard and fast are always the same, for example: {"safeLow":{"maxPriorityFee":30,"maxFee":30.000000911},"standard":{"maxPriorityFee":30,"maxFee":30.000000911},"fast":{"maxPriorityFee":30,"maxFee":30.000000911},"estimatedBaseFee":9.11e-7,"blockTime":2,"blockNumber":58464645}

ricmoo commented 4 months ago

@MatevzKlancar You will have to ask the Polygon team about that. I’m hoping someday this logic is built into the actual nodes though, so we don’t need to rely on gas station services…