我正在尝试使用ethereumjs和Infura签署和推送事务。它似乎正在工作,并且我得到了一个事务散列,但是事务在以太扫描上是不可见的,当我试图通过服务像这样推送哈希时,我会得到一个错误:
Error! Unable to broadcast Tx : {"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid RLP.","data":"RlpExpectedToBeList"},"id":1}这是我使用的代码:
var Web3 = require('web3');
var web3 = new Web3(new
Web3.providers.HttpProvider('https://ropsten.infura.io/v3/my_api_key'));
var util = require('ethereumjs-util');
var tx = require('ethereumjs-tx');
var rawTx = {
nonce: web3.toHex(1),
gasPrice: web3.toHex(20000000000),
gasLimit: web3.toHex(30000000000),
to:...
value: web3.toHex(1000000),
data: '0xc0de',
networkId: 3
};
var privateKey = '0x...';
var p = new Buffer.from(privateKey.substring(2), 'hex');
var transaction = new tx(rawTx);
transaction.sign(p);
console.log("tx hash = " + util.bufferToHex(transaction.hash(true)));我遗漏了什么?
发布于 2018-07-30 08:15:11
它是
let p = new Buffer(privateKey, "hex");当然,不要忘记序列化:
var serializedTx = "0x" + transaction.serialize().toString('hex'); 序列化的事务就是您输入到web3.eth.sendRawTransaction中的东西。
https://ethereum.stackexchange.com/questions/55104
复制相似问题