-
Ethers Version6.6.1 Search Termsalchemy,alchemyprovider Describe the ProblemThe function below, that works fine on InfuraProvider and BrowserProvider, doesn't work with AlchemyProvider. The complete error is below too. I'm using Node.js v18.16.1 and I've tried ChatGPT too and it gives me almost the same code. In the Ethers docs, we don't have a complete example, but with the pieces, the resulting code is the same. I didn't found anything about it on StackOverflow too. I'd appreciate any help. Code Snippetasync function setEthPrice(ethPriceInPenny: number): Promise<string> {
const provider = new ethers.AlchemyProvider(`${process.env.NETWORK}`, `${process.env.ALCHEMY_API_KEY}`);
const wallet = new ethers.Wallet(`${process.env.PRIVATE_KEY}`, provider);
const contract = new ethers.Contract(`${process.env.ORACLE_CONTRACT}`, oracleArtifacts.abi, wallet);
const tx = await contract.setEthPrice(ethPriceInPenny);
const receipt = await tx.wait();
console.log(tx.hash);
return tx.hash;
} Contract ABI[{
"inputs": [
{
"internalType": "uint256",
"name": "ethPriceInPenny",
"type": "uint256"
}
],
"name": "setEthPrice",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}] ErrorsTypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received an instance of Object
at checkListener (node:events:266:3)
at ClientRequest.once (node:events:647:3)
at new ClientRequest (node:_http_client:245:10)
at Object.request (node:https:360:10)
at Object.<anonymous> (/Users/luiztools/NodeProjects/web23/algodollar/backend/node_modules/agent-base/patch-core.js:25:22)
at Object.request (/Users/luiztools/NodeProjects/web23/algodollar/backend/node_modules/socks-proxy-agent/node_modules/agent-base/patch-core.js:23:20)
at getUrl (/Users/luiztools/NodeProjects/web23/algodollar/backend/node_modules/ethers/src.ts/utils/geturl.ts:31:59)
at FetchRequest.#send (/Users/luiztools/NodeProjects/web23/algodollar/backend/node_modules/ethers/src.ts/utils/fetch.ts:513:28)
at FetchRequest.send (/Users/luiztools/NodeProjects/web23/algodollar/backend/node_modules/ethers/src.ts/utils/fetch.ts:568:26)
at AlchemyProvider._send (/Users/luiztools/NodeProjects/web23/algodollar/backend/node_modules/ethers/src.ts/providers/provider-jsonrpc.ts:1147:40) {
code: 'ERR_INVALID_ARG_TYPE'
} EnvironmentAltcoin - Please specify (e.g. Polygon) Environment (Other)Polygon Mumbai |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
Here, another (and simpler) example that fires the exact same error: const provider = new ethers.AlchemyProvider( |
Beta Was this translation helpful? Give feedback.
-
Just to mention: I tried all the Ethers versions with the support of Polygon Mumbai (since 6.2, I guess). All fired the same error. I've cleaned and installed the dependencies again for each test. |
Beta Was this translation helpful? Give feedback.
-
I am getting a You error is coming from |
Beta Was this translation helpful? Give feedback.
-
You are right, thanks. I removed all the other libraries and it worked like a charm. I found that one lib specifically causes the error when used together with ethers (node-binance-api). Do you have any clue if there a way that I can isolate ethers and http from another libs? Maybe a http module copy, maybe some scope isolation, I don't know... |
Beta Was this translation helpful? Give feedback.
-
With Ethers v6, you can override the web fetching library using Do you know why they are forcing the connection over a socks5 proxy? Maybe there is a way to configure the library to skip that? |
Beta Was this translation helpful? Give feedback.
-
Inside the lib main file if I comment these two lines, everything works fine, so probably the problem is with these two and not with the node-binance-api lib itself. I didn't found a way to configure without the proxies, they always load (and probably hijack the default https and socks) when the lib is loaded. const HttpsProxyAgent = require( 'https-proxy-agent' ); |
Beta Was this translation helpful? Give feedback.
In order to resolve, I overwrote the ./patch-core.js from agent-base using the code below. So everything works fine now. Thanks for the help with the initial error.
var Module = require('module');
Module.prototype.require = new Proxy(Module.prototype.require,{
apply(target, thisArg, argumentsList){
let name = argumentsList[0];
if(/patch-core/g.test(name)){
return {};
}
return Reflect.apply(target, thisArg, argumentsList)
}
})