Skip to content

Instantly share code, notes, and snippets.

@nflaig
Last active July 17, 2023 13:04
Show Gist options
  • Save nflaig/ea5b1b3f0413cd36e4391cad110ec177 to your computer and use it in GitHub Desktop.
Save nflaig/ea5b1b3f0413cd36e4391cad110ec177 to your computer and use it in GitHub Desktop.
Call eth_estimateGas on different ELs
const ethers = require("ethers"); // v5.0.3
(async () => {
[
{ client: "Nethermind", url: "" },
{ client: "Besu", url: "" },
{ client: "Geth", url: "" },
].forEach(({ client, url }) => estimateGas(client, url));
})();
async function estimateGas(client, url) {
const provider = new ethers.providers.JsonRpcProvider(url);
const estimate = await provider.estimateGas({
from: "0x9d055dd23de15114ec95921208c741873ede8558",
to: "0xe74bc1c4c27284ab7dbcf55f71fcc04b832fc32c",
data: "0x73053410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000342f697066732f516d61624763754354786a57637a6b766f323977616d69355057435372514435656e744c62717a7a55486b79566f000000000000000000000000",
});
console.log(`${client}: ${estimate.toString()}`);
}
@emlautarom1
Copy link

I'm running Nethermind locally (http://localhost:8545) but I'm getting the following error:

/home/emlautarom1/Development/Nethermind/low-gas-fee-estimation/node_modules/@ethersproject/logger/lib/index.js:238
        var error = new Error(message);
                    ^

Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.7.2)
    at Logger.makeError (/home/emlautarom1/Development/Nethermind/low-gas-fee-estimation/node_modules/@ethersproject/logger/lib/index.js:238:21)
    at Logger.throwError (/home/emlautarom1/Development/Nethermind/low-gas-fee-estimation/node_modules/@ethersproject/logger/lib/index.js:247:20)
    at JsonRpcProvider.<anonymous> (/home/emlautarom1/Development/Nethermind/low-gas-fee-estimation/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:609:54)
    at step (/home/emlautarom1/Development/Nethermind/low-gas-fee-estimation/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:48:23)
    at Object.throw (/home/emlautarom1/Development/Nethermind/low-gas-fee-estimation/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:29:53)
    at rejected (/home/emlautarom1/Development/Nethermind/low-gas-fee-estimation/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:21:65)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  reason: 'could not detect network',
  code: 'NETWORK_ERROR',
  event: 'noNetwork'
}

Instead of using this script, could I use the Nethermind.Cli like this?

eth.estimateGas({from: "0x9d055dd23de15114ec95921208c741873ede8558", to: "0xe74bc1c4c27284ab7dbcf55f71fcc04b832fc32c", data: "0x73053410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000342f697066732f516d61624763754354786a57637a6b766f323977616d69355057435372514435656e744c62717a7a55486b79566f000000000000000000000000"})

@nflaig
Copy link
Author

nflaig commented Jul 11, 2023

I am not that familiar with Nethermind itself but I am guessing you should be able to use the CLI as well. Make sure you install ethers v5.0.3, I have not tested the script with other versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment