I want to send a test tx bundle, but bundleReceipt always is 1, output is ‘Bundle not included’
My Code (use ethers 6):
const { ethers } = require("ethers");
const {
FlashbotsBundleProvider,
} = require("@flashbots/ethers-provider-bundle");
// Flashbots relay URL
const WALLET_PRIVATE_KEY = process.env.PRIVATE_KEY;
async function main() {
// 1. Connect to Ethereum mainnet
const provider = new ethers.JsonRpcProvider(process.env.ETH_RPC);
// 2. Create wallet for sending transactions
const wallet = new ethers.Wallet(WALLET_PRIVATE_KEY, provider);
// 3. Create FlashbotsProvider
const authSigner = ethers.Wallet.createRandom();
const flashbotsProvider = await FlashbotsBundleProvider.create(
provider,
authSigner
);
// const feeData = await provider.getFeeData();
const maxFeePerGas = ethers.parseUnits("200", "gwei");
const maxPriorityFeePerGas = ethers.parseUnits("5", "gwei");
// 4. Construct transaction (example: transfer from one address to another)
const tx = {
to: "0xB4E71a8CbB66924Bd954C3c42F99694862096241", // Recipient address
value: ethers.parseEther("0.01"), // Send 0.01 ETH
gasLimit: 510000, // Standard gas limit for transfer
maxFeePerGas, // Add maxFeePerGas
maxPriorityFeePerGas, // Add maxPriorityFeePerGas
chainId: 1,
};
const blockNumber = await provider.getBlockNumber();
const bundle = [
{
signer: wallet,
transaction: tx,
},
];
const signedBundle = await flashbotsProvider.signBundle(bundle);
// simulate
const simulationResponse = await flashbotsProvider.simulate(
signedBundle,
blockNumber + 1
);
if ("error" in simulationResponse) {
console.error("Simulation error:", simulationResponse.error.message);
} else {
console.log("Simulation successful");
}
// 6. Send bundled transaction to Flashbots
const bundleResponse = await flashbotsProvider.sendBundle(
bundle,
blockNumber + 1 // Current block number
);
// Check Flashbots transaction response
if ("error" in bundleResponse) {
console.error(`Flashbots Error: ${bundleResponse.error.message}`);
return;
}
const bundleReceipt = await bundleResponse.wait();
if (bundleReceipt === 0) {
console.log(`Bundle was included in block ${bundleReceipt}`);
} else if (bundleReceipt === 1) {
console.log(`Bundle not included`);
} else {
console.log(`Nonce too high`);
}
}
main()
.then(() => console.log("Flashbots Bundle Script Completed"))
.catch((err) => console.error(err));