My program needs to know how the transactions in the mempool will affect the state when mined. Does anyone know of any tools to help with this? I know I can do it manually with ganache --fork, but I don't know a good way to automate it without starting from scratch
1 Answer
You can interact directly with the ganache-core
library: github
Below is a test with using the infura API. This also works with a local node.
const ganache = require("ganache-core");
const Web3 = require("web3");
// set whatever options you'd use in the cli here
const options = {
fork: "https://ropsten.infura.io/v3/API_KEY",
port: 6546,
};
const server = ganache.server(options);
const provider = server.provider;
const web3 = new Web3(provider);
web3.eth.getBalance("0x635B4764D1939DfAcD3a8014726159abC277BecC")
.then(console.log);
web3.eth.getBlockNumber()
.then(console.log);