我目前正在编写一个函数来创建和广播原始的以太坊交易。我能够成功生成原始事务,但是当我将其发送到网络时,它不会被处理。以下是我的代码:
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)
})
}