How to use Bundle
This guide explains how to submit transaction bundles on BNB Smart Chain using GetBlock's MEV endpoint.
Prerequisites
Sample Request
wss://go.getblock.io/<ACCESS_TOKEN>Parameter
Type
Required
Description
{
"jsonrpc": "2.0",
"id": 1,
"method": "mev_sendBundle",
"params": {
"transactions": ["0xf86c...", "0xf86c..."],
"mev_builders": { "all": "" },
"blocks_count": 5
}
}{
"jsonrpc": "2.0",
"id": 1,
"result": {
"bundleHash": "0x..."
}
}Example
1
mkdir bundle-example
cd bundle-example
npm init -y
npm install ws ethers dotenvmkdir bundle-example
cd bundle-example
yarn init -y
yarn ws ethers dotenv2
3
4
ACCESS_TOKEN=your-accelerated-node-endpoint
RPC_URL=your-normal-bsc-node-endppoint //e.g https
PRIVATE_KEY=your-wallet-private-key5
import WebSocket from "ws";
import { ethers } from "ethers";
import "dotenv/config";
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const RPC_URL = process.env.RPC_URL;
async function submitBundle() {
const provider = new ethers.JsonRpcProvider(RPC_URL);
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
// Get the current nonce for your wallet
const nonce = await provider.getTransactionCount(wallet.address);
// Transaction 1: First operation
const tx1 = await wallet.signTransaction({
nonce: nonce,
to: DEX_A,
value: ethers.parseEther("0.001"),
data: buyCalldata,
gasPrice: ethers.parseUnits("3", "gwei"),
gasLimit: 300000,
chainId: 56,
});
// Transaction 2: Second operation (must use nonce + 1)
const tx2 = await wallet.signTransaction({
nonce: nonce + 1,
to: DEX_B,
value: 0,
data: sellCalldata,
gasPrice: ethers.parseUnits("3", "gwei"),
gasLimit: 300000,
chainId: 56,
});
// Connect to the MEV endpoint
const ws = new WebSocket(process.env.ACCESS_TOKEN);
ws.on("open", () => {
ws.send(
JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "mev_sendBundle",
params: {
transactions: [tx1.slice(2), tx2.slice(2)],
mev_builders: { all: "" },
blocks_count: 5,
},
}),
);
});
ws.on("message", (data) => {
const response = JSON.parse(data);
if (response.result) {
console.log("Bundle submitted successfully");
console.log("Bundle Hash:", response.result.bundleHash);
} else {
console.error("Submission failed:", response.error);
}
ws.close();
});
}
submitBundle();6
node index.js7
Example: DEX Arbitrage
Comparing Bundles and Private Transactions
Best Practices
Choose an Appropriate blocks_count Value
Use Case
Recommended blocks_count
Simulate Before Submitting
Troubleshooting
Problem
Solution
Last updated
Was this helpful?