2

我目前正在编写一个函数来创建和广播原始以太坊交易。我能够成功生成原始交易,但是当我将其发送到网络时,它没有得到处理。下面是我的代码:

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'))
}

和广播的代码:

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)
    })
}
4

0 回答 0