raw transaction not broadcasting

256 views Asked by At

I am currently writing a function to create and broadcast a raw ethereum transaction. I am able to successfully generate the raw transaction but when I go to send it off to the network it is not processed. Below is my code:

function createRawTransacton() {
    var privateKey = new Buffer('xxx', 'hex')
    var rawTx = {
        nonce: 'CX350',
        gasPrice: 'C350',
        gasLimit: '0x3d0900',
        to: '0xc5622be5861b7200cbace14e28b98c4ab77bd9b4',
        value: 'CX350',
        data: '0x19dacbf83c5de6658e14cbf7bcae5c15eca2eedecf1c66fbca928e4d351bea0f'
    }
    var tx = new Tx(rawTx)
    tx.sign(privateKey)
    var serializedTx = tx.serialize()
    console.log(serializedTx.toString('hex'))
    broadCastTx(serializedTx.toString('hex'))
}

and the code to broadcast:

function broadCastTx(hex) {
    var query = "https://testnet.etherscan.io/api?module=proxy&action=eth_sendRawTransaction&hex="
    query += hex;
    query += "&apikey=xxx'"
    request.get(query, (err, data) => {
        console.log(data.body)
    })
}
0

There are 0 answers