How to Submit Transactions to Public Mempool
Learn how to submit transactions to the BNB Chain public mempool through GetBlock's BDN fast path.
When to Use Public Mempool
Sample Request
wss://go.getblock.io/<ACCESS_TOKEN>eth_sendRawTransactionParameter
Type
Required
Description
{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_sendRawTransaction",
"params": ["0x<signed_transaction_hex>"]
}{
"jsonrpc": "2.0",
"id": 1,
"result": "0x<transaction_hash>"
}How to Submit Transaction to Publoc Mempool
1
mkdir transaction-public-mempool
cd transaction-public-mempool
npm init -y
npm install ws ethers dotenvmkdir transaction-public-mempool
cd transaction-public-mempool
yarn init -y
yarn ws ethers dotenv2
3
4
5
import WebSocket from 'ws';
import ethers from 'ethers';
import 'dotenv/config';
const PRIVATE_KEY = 'YOUR_PRIVATE_KEY';
const RPC_URL = 'https://bsc-dataseed.binance.org';6
const provider = new ethers.JsonRpcProvider(RPC_URL);
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
// Get current nonce
const nonce = await provider.getTransactionCount(wallet.address);
// Build transaction
const tx = {
nonce: nonce,
to: '0xRECIPIENT_ADDRESS',
value: ethers.parseEther('0.1'),
gasPrice: ethers.parseUnits('3', 'gwei'), // Minimum 3 gwei for BSC
gasLimit: 21000,
chainId: 56 // BSC Mainnet
};
// Sign transaction
const signedTx = await wallet.signTransaction(tx);7
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: 'eth_sendRawTransaction',
params: [signedTx]
}));
});
ws.on('message', (data) => {
const response = JSON.parse(data);
if (response.result) {
console.log('✅ Transaction submitted!');
console.log('TX Hash:', response.result);
console.log('BSCScan:', `https://bscscan.com/tx/${response.result}`);
} else if (response.error) {
console.error('❌ Error:', response.error.message);
}
ws.close();
});8
Gas Price Recommendations
Priority
Gas Price
Use Case
Troubleshooting
Next Steps
Last updated
Was this helpful?