web3.eth.getChainId((err, chainid) => { if (err != null) { console.log('区块链ID:' + chainid + ' 错误信息:' + err) return } web3.eth.getTransactionCount(_from, 'latest', (error, txCount) => { if (!error) { const customCommon = Common.forCustomChain( 'mainnet', { name: 'HUI', networkId: 8888, chainId: 8888 }, 'petersburg' ) var rawTx = { from: '0xeE3feFf2B426c118C7878be4ff16D11ba894E344', nonce: web3.utils.toHex(txCount +=27), gasPrice: web3.utils.toHex(40), gasLimit: web3.utils.toHex(8000000), to: '0x1C6De259D344b3bA51eAE7700f3EFf3aF4f01B42', value: '0x0', data: contractObj.methods.transfer(toAddress, sendNum).encodeABI(), chainId: web3.utils.toHex(chainid) } console.log('nonce-->', rawTx.nonce);
var tx = new Tx(rawTx, { common: customCommon });
tx.sign(pv);
const serializedTx = tx.serialize()
console.log('data-->', serializedTx.toJSON())
// console.log('==>', rawTx.serialize().toJSON().data.toString())
// console.log('Senders Address: ' + tx.getSenderAddress().toString('hex'))
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'), function (err, hash) {
console.log('err-->', err);
console.log('hash-->', hash);
})
.on('receipt', console.log);
}
})
})