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
import WebSocket from 'ws';
import { ethers } from 'ethers';
import 'dotenv/config';
const PRIVATE_KEY = 'YOUR_PRIVATE_KEY';
async function submitBundle() {
const provider = new ethers.JsonRpcProvider('https://bsc-dataseed.binance.org');
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('1.0'),
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(`wss://go.getblock.io/${process.env.ACCESS_TOKEN}`);
ws.on('open', () => {
ws.send(JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'mev_sendBundle',
params: {
transactions: [tx1, tx2],
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();5
node index.js6
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?