我同时通过联系人发送一些交易。但是块执行其中一个因为两个事务具有相同的nonce(我从getTransactionCount获得)。我该如何解决?
每次创建交易时都会使用此代码:
var token = web3.eth.contract(config.contract.abi).at(config.contract.address);
var payloadData = token.transfer.getData(address, amount);
gasPrice = web3.eth.gasPrice;
gasPriceHex = web3.toHex(gasPrice);
gasLimitHex = web3.toHex(gaslimit);
console.log('Current gasPrice: ' + gasPrice + ' OR ' + gasPriceHex);
nonce = web3.eth.getTransactionCount(config.account.address);
nonceHex = web3.toHex(nonce);
console.log('nonce (transaction count on fromAccount): ' + nonce + '(' + nonceHex + ')');
var rawTx = {
nonce: nonceHex,
gasPrice: gasPriceHex,
gasLimit: gasLimitHex,
to: config.contract.address,
from: config.account.address,
value: '0x00',
data: payloadData
};
var tx = new Tx(rawTx);
tx.sign(Buffer.from(config.account.privateKey, 'hex'));
var serializedTx = tx.serialize();
web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function (err, hash) {
if (err) {
console.log(err);
console.log(hash);
}
});