ethers.js
ethers.js copied to clipboard
InfuraProvider logger should deal with the projectID limit
Ethers Version
5.6.0
Search Terms
InfuraProvider
Describe the Problem
When using an Infura projectID that exceeded the daily cap, ethers throw a timeout rather than the relevant error "exceeded project daily request limit"
Repro:
- Set a small "PER DAY TOTAL REQUESTS" limit (ex. 3) in the specific Infura projectID security settings
- Run the script below a few times
Code Snippet
const { ethers } = require("ethers");
const provider = new ethers.providers.InfuraProvider(
"mainnet",
"XXXX"
);
provider.getBlockNumber().then(console.log);
Contract ABI
No response
Errors
Error: timeout (requestBody="{\"method\":\"eth_blockNumber\",\"params\":[],\"id\":42,\"jsonrpc\":\"2.0\"}", requestMethod="POST", timeout=120000, url="https://mainnet.infura.io/v3/XXXX", code=TIMEOUT, version=web/5.6.0)
at Logger.makeError (/...node_modules/@ethersproject/logger/lib/index.js:233:21)
at Timeout._onTimeout (/...node_modules/@ethersproject/web/lib/index.js:179:35)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
reason: 'timeout',
code: 'TIMEOUT',
requestBody: '{"method":"eth_blockNumber","params":[],"id":42,"jsonrpc":"2.0"}',
requestMethod: 'POST',
timeout: 120000,
url: 'https://mainnet.infura.io/v3/XXX'
}
Environment
node.js (v12 or newer)
Environment (Other)
No response
This is also happening when using JsonRpcProvider. My ethers version is 5.6.1.
Code snippet:
const { ethers } = require("ethers");
provider = new ethers.providers.JsonRpcProvider(`https://mainnet.infura.io/v3/MY_PROJECT_ID`);
provider.getBlockNumber().then(console.log)
Full error code:
Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.6.1)
at Logger.makeError (/Users/christian/node_modules/@ethersproject/logger/lib/index.js:233:21)
at Logger.throwError (/Users/christian/node_modules/@ethersproject/logger/lib/index.js:242:20)
at JsonRpcProvider.<anonymous> (/Users/christian/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:517:54)
at step (/Users/christian/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:48:23)
at Object.throw (/Users/christian/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:29:53)
at rejected (/Users/christian/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:21:65) {
reason: 'could not detect network',
code: 'NETWORK_ERROR',
event: 'noNetwork'
I don't know there is much that ethers can do in this case? The JsonRpcProvider definitely won't be able to process INFURA-specific messages, but the InfuraProvider could possibly annotate the SERVER_ERROR.
is there any update? I would like to understand how to identify when I have reached the daily limit of requests.
it's currently timing out, I'm not getting any errors.
Hi, I think this is not a daily limit issue but a timeout issue. RPC has by default a timeout of 120000 ms. You can set a custom timeout in the Provider network config object:
const provider = new ethers.providers.JsonRpcProvider({
url: config.providerURLDebug,
timeout: config.timeout
});