Skip to content

Instantly share code, notes, and snippets.

@TomiOhl
Last active May 27, 2024 17:06
Show Gist options
  • Save TomiOhl/1b136f8acdd82378ce6c9f598cc9f1cc to your computer and use it in GitHub Desktop.
Save TomiOhl/1b136f8acdd82378ce6c9f598cc9f1cc to your computer and use it in GitHub Desktop.
Test RPC calls via ether-proxy and direct RPC calls via ethers.js. Should be run on Ethereum and as a Hardhat script
// eslint-disable-next-line import/no-extraneous-dependencies, node/no-extraneous-import
import axios from "axios";
import { ethers } from "hardhat";
const payloads = [
{
jsonrpc: "2.0",
id: 2,
method: "eth_chainId",
params: []
},
{
jsonrpc: "2.0",
id: 2,
method: "eth_blockNumber",
params: []
},
{
jsonrpc: "2.0",
id: 2,
method: "eth_getBalance",
params: ["0x21a31Ee1afC51d94C2eFcCAa2092aD1028285549", "latest"]
},
{
jsonrpc: "2.0",
id: 2,
method: "eth_getTransactionCount",
params: ["0x14DDFE8EA7FFc338015627D160ccAf99e8F16Dd3", "latest"]
},
// {
// jsonrpc: "2.0",
// method: "eth_getBlockTransactionCountByNumber",
// params: ["latest"]
// },
{
jsonrpc: "2.0",
id: 2,
method: "eth_call",
params: [{ to: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", data: "0x06fdde03" }, "latest"]
},
{
jsonrpc: "2.0",
id: 2,
method: "eth_call",
params: [{ to: "0x458691c1692CD82faCfb2C5127e36D63213448A8", data: "0x06fdde03" }, "latest"]
},
{
jsonrpc: "2.0",
method: "eth_call",
id: 2,
params: [
{
from: "0x7CD8C45A83d97d74bbd6b94c307919DD6600Ccec",
to: "0x6ee2dD02FBFb71F518827042B6aDca242F1ba0B2",
data: "0xfd7c37b4000000000000000000000000000000000000000000000000000000000000000100000000000000000000000073d1a63bce3083be47597e2ef0646bbfd1907f1c"
},
"latest"
]
}
// {
// jsonrpc: "2.0",
// id: 2,
// method: "eth_getLogs",
// params: [
// {
// fromBlock: "0x12f81d0",
// toBlock: "0x12f81da",
// address: "0x6ee2dd02fbfb71f518827042b6adca242f1ba0b2",
// topics: ["0x209ee1cca29d8cb121d84438eff8a3148751f32436e76569f31aae0e4a89bf6a", null, null, null]
// }
// ]
// },
];
async function main() {
await Promise.all(
payloads.map(async (payload) => {
const viaEthers = await ethers.provider.send(payload.method, payload.params);
const {
data: { result: viaEtherProxy }
} = await axios.post("http://127.0.0.1:8321/api/ethereum", payload);
console.log(
payload.method,
"\nethers: ",
viaEthers,
"\nether-proxy: ",
viaEtherProxy,
"\nequal: ",
viaEthers === viaEtherProxy ? "✅️" : "❌️",
"\n"
);
})
);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment