转账部分的代码:
let txObject = {
nonce: web3js.utils.toHex(txCount),
from: from_address,
to: coins[contract_name].address,
gasLimit: web3js.utils.toHex(550000),
gasPrice: web3js.utils.toHex(web3js.utils.toWei('10', 'gwei')),
data: contractData,
}
const privateKey = Buffer.from(mainAddressSecret, 'hex');
const tx = new Tx(txObject, config.chain.getChain());
tx.sign(privateKey);
const serializedTx = tx.serialize()
const raw = '0x' + serializedTx.toString('hex');
web3js.eth.sendSignedTransaction(raw, (error, txHash) => {
if (!error) {
resolve(txHash);
} else {
ferror("send error" + error);
reject("error: " + error);
}
});
发起转账后web3js.eth.sendSignedTransaction 都能获取到结果hash,大部分都能转账成功,链上可以查到,但是有时候转账不成功,链上也查不到相关hash的信息。 还请懂得朋友指点指点,谢谢。