githubEdit

How to Submit Transactions to Public Mempool

Learn how to submit transactions to the BNB Chain public mempool through GetBlock's BDN fast path.

This process involves submitting transactions to the BNB Chain public mempool via GetBlock's BDN fast path. Your transaction propagates to validators significantly faster than through standard P2P gossip, increasing the probability of earlier block inclusion.

When to Use Public Mempool

Use public mempool submission when:

  • You want faster propagation without hiding your transaction

  • MEV exposure is acceptable for your use case

  • You're competing on speed rather than privacy

  • You need broad validator visibility quickly

For MEV-sensitive transactions, see Private Transactions instead.

Sample Request

wss://go.getblock.io/<ACCESS_TOKEN>

How to Submit Transaction to Publoc Mempool

1

Set up the project

mkdir transaction-public-mempool
cd transaction-public-mempool
npm init -y
npm install ws ethers dotenv
2

Create a new file named index.js. This is where you will make your first call.

3

Set the ES module "type": "module" in your package.json.

4

Add the following code to index.js:

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

Create and Sign Your Transaction

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

Submit via WebSocket

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

Response

chevron-rightComplete Example: BNB Transferhashtag
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';

async function sendPublicTransaction(recipient, amountBNB) {
  const provider = new ethers.JsonRpcProvider(RPC_URL);
  const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
  
  console.log('Wallet:', wallet.address);
  console.log('Recipient:', recipient);
  console.log('Amount:', amountBNB, 'BNB');
  
  // Get nonce
  const nonce = await provider.getTransactionCount(wallet.address);
  
  // Build transaction
  const tx = {
    nonce: nonce,
    to: recipient,
    value: ethers.parseEther(amountBNB),
    gasPrice: ethers.parseUnits('3', 'gwei'),
    gasLimit: 21000,
    chainId: 56
  };
  
  // Sign transaction
  const signedTx = await wallet.signTransaction(tx);
  console.log('\nTransaction signed');
  
  // Submit via BDN
const ws = new WebSocket(`wss://go.getblock.io/${process.env.ACCESS_TOKEN}`);
  
  return new Promise((resolve, reject) => {
    ws.on('open', () => {
      console.log('Submitting to BDN...');
      
      ws.send(JSON.stringify({
        jsonrpc: '2.0',
        id: 1,
        method: 'eth_sendRawTransaction',
        params: [signedTx]
      }));
    });
    
    ws.on('message', (data) => {
      const response = JSON.parse(data);
      ws.close();
      
      if (response.result) {
        console.log('\n✅ Transaction submitted!');
        console.log('TX Hash:', response.result);
        console.log('BSCScan:', `https://bscscan.com/tx/${response.result}`);
        resolve(response.result);
      } else {
        console.error('\n❌ Error:', response.error);
        reject(response.error);
      }
    });
    
    ws.on('error', (err) => {
      reject(err);
    });
  });
}

// Usage
sendPublicTransaction(
  '0xRECIPIENT_ADDRESS',
  '0.1'  // 0.1 BNB
).catch(console.error);

chevron-rightComplete Example: Token Swap on PancakeSwaphashtag

Gas Price Recommendations

Priority
Gas Price
Use Case

Standard

3 gwei

Regular transfers

Fast

5 gwei

Time-sensitive trades

Urgent

10+ gwei

Competitive scenarios

circle-info

Note: Higher gas prices increase inclusion priority but also increase transaction cost.

Troubleshooting

  1. "nonce too low"

Your nonce is behind the network state. Fetch the latest:

  1. "insufficient funds"

Ensure you have enough BNB for both the transaction value and gas:

  1. "replacement transaction underpriced"

If replacing a pending transaction, increase the gas price by at least 10%:

  1. Transaction not included

  • Increase gas price for higher priority

  • Check that the transaction is valid

  • Verify sufficient balance

Next Steps

For transactions that need MEV protection, see:

Last updated

Was this helpful?