Binance Smart Chain (BSC)
  • Introduction
  • web3 on BSC
    • gas
    • wallet-balance
    • BEP20 tokens lists
    • transfer
    • broadcast
Powered by GitBook
On this page

Was this helpful?

  1. web3 on BSC

broadcast

Broadcast any signed txn on Binance Smart Chain

/bsc/broadcast

POST https://cryptotalk-public-gateway-byeii62k.de.gateway.dev/bsc/broadcast

Code example is given below

Query Parameters

Name
Type
Description

key

string

API Key

Request Body

Name
Type
Description

params

object

{ "addr" : "0xabcd...efe", "serializedTx" : "0xf8aa048....c", "operation" : "BROADCAST" }

{
  "operation": "BROADCAST",
  "isError": false,
  "errorMsg": "Txn broadcasted successfully",
  "data": "https://bscscan.com/tx/0x5979c5de32b803d15ead4b450161d6f9ba127a7c6d10a4121375222c840520bf"
}
async function broadcast(){
    const fetch                 = require('node-fetch');
    const web3js                = require('web3');
    const BROADCAST_URL         = "https://cryptotalk-public-gateway-byeii62k.de.gateway.dev/bsc/broadcast";
    const API_KEY               = "AIzaSyCngkz41JSdBMlr4iKqAMLiTMHD9TfQvuc";
    const bscWeb3               = new web3js('https://bsc-dataseed.binance.org/');

    const Private_key           = "....wallet private key... ";
    const my_wallet_addr        = "0x5585D5365F37671Eecc0FDCAC5a06BD1d176408E";
    
    const rawTx                 = {
                                    from: '0x5585d5365f37671eecc0fdcac5a06bd1d176408e',
                                    value: '0x0',
                                    to: '0xe9e7cea3dedca5984780bafc599bd69add087d56',
                                    data: '0xa9059cbb00000000000000000000000066eb772458fc2743c5e3adb232dc18ef3a80d5800000000000000000000000000000000000000000000000008ac7230489e80000',
                                    nonce: '0xf16',
                                    gasLimit: '0x7a120',
                                    gasPrice: '0x2540be400'
                                }

    const signedTx              = await bscWeb3.eth.accounts.signTransaction(rawTx, Private_key);

    const request_body          = {
                                    "addr" 		   : my_wallet_addr,
                                    "serializedTx" : (signedTx.raw || signedTx.rawTransaction),
                                    "operation"    : "BROADCAST"
                                };

    let txn_response            = await fetch(BROADCAST_URL +"?key=" + API_KEY, 
                                                { method : 'post', 
                                                  body   : JSON.stringify({ params : request_body}), 
                                                  headers: { 'Content-Type': 'application/json'}
                                                }
                                            );
    let tx                      = await txn_response.json();
    if(tx.isError){
        console.error("Error");
    }else{
        console.log(tx.data);
    }
}
Previoustransfer

Last updated 4 years ago

Was this helpful?