0

Hi I am having an issue in flashbotsProvider.simulate() while pushing a transaction to the miners to be send to the block without sending it to the mempool. Below is my source code

// 1. Import everything
const { Wallet, BigNumber, ethers, providers } = require("ethers");
const {
  FlashbotsBundleProvider,
  FlashbotsBundleResolution,
} = require("@flashbots/ethers-provider-bundle");

/*
Mainnet
const provider = new providers.JsonRpcProvider('https://eth-mainnet.g.alchemy.com/v2/cmHEQqWnoliAP0lgTieeUtwHi0KxEOlh')
const wsProvider = new providers.WebSocketProvider('wss://eth-mainnet.g.alchemy.com/v2/cmHEQqWnoliAP0lgTieeUtwHi0KxEOlh')
*/

// 2. Setup a standard provider in goerli
const provider = new providers.JsonRpcProvider(
  "https://nd-310-829-335.p2pify.com/80879fdceecc547dc9a9b6a72a1d3a99"
);
const wsProvider = new providers.WebSocketProvider(
  "wss://ws-nd-310-829-335.p2pify.com/80879fdceecc547dc9a9b6a72a1d3a99"
);

// 3. The unique ID for flashbots to identify you and build trust over time
const authSigner = new Wallet(
  "<<my private key>>",
  provider
);
// The address of the authSigner is 0x09Dad4e56b1B2A7eeD9C41691EbDD4EdF0D80a46

const start = async () => {
  // 4. Create the flashbots provider
  const flashbotsProvider = await FlashbotsBundleProvider.create(
    provider,
    authSigner,
    "https://relay-goerli.epheph.com/"
  );

  const GWEI = BigNumber.from(10).pow(9);
  const LEGACY_GAS_PRICE = GWEI.mul(1);
  const PRIORITY_FEE = GWEI.mul(100);
  const blockNumber = await provider.getBlockNumber();
  const block = await provider.getBlock(blockNumber);
  const maxBaseFeeInFutureBlock =
    FlashbotsBundleProvider.getMaxBaseFeeInFutureBlock(block.baseFeePerGas, 6); // 100 blocks in the future

  console.log(
    "maxBaseFeeInFutureBlock",
    String(maxBaseFeeInFutureBlock),
    String(maxBaseFeeInFutureBlock.div("100000000000000000"))
  );

  const amountInEther = "0.001";
  // 5. Setup the transactions to send and sign
  const signedTransactions = await flashbotsProvider.signBundle([
    {
      // Both transactions are the same but one is type 1 and the other type 2 after the gas changes
      signer: authSigner,
      transaction: {
        to: "0x2c3fF32c7F6C7f83fFd13C76Cfef67C0E9811240",
        type: 2,
        maxFeePerGas: PRIORITY_FEE.add(maxBaseFeeInFutureBlock),
        maxPriorityFeePerGas: PRIORITY_FEE,
        data: "0x",
        chainId: 5,
        value: ethers.utils.parseEther(amountInEther),
        // gasLimit: 300000,
      },
    },
    // we need this second tx because flashbots only accept bundles that use at least 42000 gas.
    {
      signer: authSigner,
      transaction: {
        to: "0x2c3fF32c7F6C7f83fFd13C76Cfef67C0E9811240",
        gasPrice: LEGACY_GAS_PRICE,
        data: "0x",
        value: ethers.utils.parseEther(amountInEther),
        // gasLimit: 300000,
      },
    },
  ]);

  // 6. We run a simulation for the next block number with the signed transactions
  console.log(new Date());
  console.log("Starting to run the simulation...");
  console.log(blockNumber);

  //simulation is a need that our transactions are given to the miners and miners include them in a block without going in to the mempool ; that's prevent from front run attacks
  const simulation = await flashbotsProvider.simulate(
    signedTransactions,
    blockNumber
  );
  console.log("simulation: ", simulation);
  console.log(new Date());

  // 7. Check the result of the simulation
  if (simulation.firstRevert) {
    console.log(`Simulation Error: ${simulation.firstRevert.error}`);
  } else {
    console.log(`Simulation Success: ${blockNumber}}`);
  }

  // 8. Send 10 bundles to get this working for the next blocks in case flashbots doesn't become the block producer
  for (var i = 1; i <= 10; i++) {
    const bundleSubmission = await flashbotsProvider.sendRawBundle(
      signedTransactions,
      blockNumber + i
    );
    console.log("bundle submitted, waiting", bundleSubmission.bundleHash);

    const waitResponse = await bundleSubmission.wait();
    console.log(`Wait Response: ${FlashbotsBundleResolution[waitResponse]}`);
    if (
      waitResponse === FlashbotsBundleResolution.BundleIncluded ||
      waitResponse === FlashbotsBundleResolution.AccountNonceTooHigh
    ) {
      console.log("Bundle included!");
      process.exit(0);
    } else {
      console.log({
        bundleStats: await flashbotsProvider.getBundleStatsV2(
          simulation.bundleHash,
          blockNumber + 1
        ),
        userStats: await flashbotsProvider.getUserStatsV2(),
      });
    }
  }
  console.log("bundles submitted");
};

start(); 

And below is the error i am troubleshooting

Error: timeout (requestBody="{\"method\":\"eth_callBundle\",\"params\":[{\"txs\":[\"0x02f873053a85174876e80085174876e838825208942c3ff32c7f6c7f83ffd13c76cfef67c0e981124087038d7ea4c6800080c080a0a0a6b80afe6998529f1802e77452e8f0275ade04636168287927696e1a75efb1a019e24a48e7c2c17cf9a36ead2c352c1058cd5a6f773aadb4f797e61dd5baa275\",\"0xf86a3b843b9aca00825208942c3ff32c7f6c7f83ffd13c76cfef67c0e981124087038d7ea4c68000801ba0b7eba45311be85c946d12f604eb16f991626556ac95e7ddb5c8d965cfb85ca21a04b9392efe493190df3ed4f4f637df7ceba967a95e6bd2f9597ed28c7834fadff\"],\"blockNumber\":\"0x9ce9f8\",\"stateBlockNumber\":\"latest\"}],\"id\":42,\"jsonrpc\":\"2.0\"}", requestMethod="POST", timeout=120000, url="https://relay-goerli.epheph.com/", code=TIMEOUT, version=web/5.7.1)
    at Logger.makeError (/home/muhammad/Desktop/Arbitrage/node_modules/@ethersproject/logger/lib/index.js:238:21)
    at Timeout._onTimeout (/home/muhammad/Desktop/Arbitrage/node_modules/@ethersproject/web/lib/index.js:187:35)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7) {
  reason: 'timeout',
  code: 'TIMEOUT',
  requestBody: '{"method":"eth_callBundle","params":[{"txs":["0x02f873053a85174876e80085174876e838825208942c3ff32c7f6c7f83ffd13c76cfef67c0e981124087038d7ea4c6800080c080a0a0a6b80afe6998529f1802e77452e8f0275ade04636168287927696e1a75efb1a019e24a48e7c2c17cf9a36ead2c352c1058cd5a6f773aadb4f797e61dd5baa275","0xf86a3b843b9aca00825208942c3ff32c7f6c7f83ffd13c76cfef67c0e981124087038d7ea4c68000801ba0b7eba45311be85c946d12f604eb16f991626556ac95e7ddb5c8d965cfb85ca21a04b9392efe493190df3ed4f4f637df7ceba967a95e6bd2f9597ed28c7834fadff"],"blockNumber":"0x9ce9f8","stateBlockNumber":"latest"}],"id":42,"jsonrpc":"2.0"}',
  requestMethod: 'POST',
  timeout: 120000,
  url: 'https://relay-goerli.epheph.com/'
}

Node.js v21.2.0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.