以下是我的代码,我的网络没有问题,私钥也没有问题。当然,密钥库路径也是正确的。我不知道我的项目发生了什么。我希望你能给出答案来解决我的问题。
function Asset () {
this.index = Asset.prototype.index++;
}
以下是我遇到的问题:
var Web3 = require("web3");
const bip39 = require('bip39');
var fs = require("fs");
var keythereum = require("keythereum");
var EthereumTx = require('ethereumjs-tx');
var ethereumjsWallet = require('ethereumjs-wallet');
if (typeof web3 !== 'undefined')
{
web3 = new Web3(web3.currentProvider);
}
else
{
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
var keystore = fs.readFileSync('/Users/guo/Library/Ethereum/keystore/UTC--2018-06-01T04-28-05.856252000Z--fa8c86b4855f756b280b39870b8d876db20627eb').toString();
var pass = "********";
var wallet = ethereumjsWallet.fromV3(keystore, pass);
var privateKey = wallet.getPrivateKey();
console.info("private key : " + privateKey)
const privateKey1 = Buffer.from(privateKey, 'hex')
console.log(privateKey1);
var rawTx = {
nonce: '0x1F',
gasPrice: '0x9184e72a000.',
gasLimit: '0x2710',
to: '0x1f26a937aebbcf4652c41e080ad139ac1b253b3a',
value: '0x186a0',
data: '0x7f746573743200000000000000000000',
chainId:"8054",
};
var tx = new EthereumTx(rawTx);
tx.sign(privateKey1);
var serializedTx = tx.serialize();
web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function (err, hash)
{
console.log('transaction id :'+ hash);
console.log(err);
});