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://shared.eu-central-1.getblock.io/<ACCESS_TOKEN>blxr_txParameter
Type
Required
Description
{
"jsonrpc": "2.0",
"id": 1,
"method": "blxr_tx",
"params": ["0x<signed_transaction_hex>"]
}{
"jsonrpc": "2.0",
"id": 1,
"result": "0x<transaction_hash>"
}How to Submit a Transaction to Public 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
ACCESS_TOKEN=your-accelerated-node-endpoint
RPC_URL=your-normal-bsc-node-endppoint //e.g https
PRIVATE_KEY=your-wallet-private-key
TO_ADDRESS=the-receiver-address5
6
import WebSocket from "ws";
import { ethers } from "ethers";
import "dotenv/config";7
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const RPC_URL = process.env.RPC_URL;
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: process.env.TO_ADDRESS,
value: ethers.parseEther("0.001"),
gasPrice: ethers.parseUnits("3", "gwei"), // Minimum 3 gwei for BSC
gasLimit: 21000,
chainId: 56, // BSC Mainnet
};
// Sign transaction
const signedTx = await wallet.signTransaction(tx);
const signedTxNoPrefix = signedTx.startsWith("0x")
? signedTx.slice(2)
: signedTx;8
const ws = new WebSocket(process.env.ACCESS_TOKEN);
ws.on("open", () => {
ws.send(
JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "blxr_tx",
params: {"transaction": signedTxNoPrefix},
}),
);
});
ws.on("message", (data) => {
const response = JSON.parse(data);
if (response.result?.txHash) {
const hash = response.result.txHash;
console.log("TX Hash:", hash);
console.log(`https://bscscan.com/tx/${hash}`);
} else if (response.error) {
console.error("❌ Error:", response.error.message);
}
ws.close();
});9
01f86c380384b2d05e0082520894d26ea0f03100358b2ebd4c9638f042aada9a1bcf87038d7ea4c6800080c001a04647f98754480337ae409bcc225f2d62b706b47f31385221421cea20e41080b0a03ae32f07bb7110c4153c2ab121c152db7d3030d54cc0c5341f0b75b20e3d439d
TX Hash: 00d4fe2db5c667ce549318cf621913af1bcb130022ec51020cbb6cae2b7eedce
https://bscscan.com/tx/00d4fe2db5c667ce549318cf621913af1bcb130022ec51020cbb6cae2b7eedceGas Price Recommendations
Priority
Gas Price
Use Case
Troubleshooting
Next Steps
Last updated
Was this helpful?