web3 on react-native : Error: Returned error: insufficient funds for gas * price + value

web3 on react-native : Error: Returned error: insufficient funds for gas * price + value

使用 web3@1.0.0-beta.33react-native@0.59.10,因为最新的 web3react-native 上有安装问题,经过深入研究 1.0.0-beta.33 适用于 react-native

const web3 = new Web3("https://mainnet.infura.io:443"); 
var count = await web3.eth.getTransactionCount(this.state.selectedWallet.publicaddress);
var contractdata = new web3.eth.Contract(abiArray, SensitiveInfo.tokencontract);
var rawTransaction = {
    "from": this.state.selectedWallet.publicaddress,
    "nonce": count,
    "gasPrice": 4500000000,
    "gas": web3.utils.toHex("519990"),
    "gasLimit":web3.utils.toHex("519990"),
    "to": SensitiveInfo.tokencontract,
    "value": "0x0",
    "data": contractdata.methods.transfer(this.state.recipientaddress,web3.utils.toWei('1', 'ether')).encodeABI(),
    "chainId": 0x01
};
var privKey = new Buffer(this.state.selectedWallet.privatekey,'hex');
var tx = new Tx(rawTransaction);
tx.sign(privKey);
var serializedTx = tx.serialize();
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'), (err, hash) =>{
  if (!err) //SUCCESS
      console.log(hash);
  else
      console.log(err);
});    

}

备注

  1. Web 中使用的相同代码库是有效的,但是 web3@1.2.1
  2. 我可以非常确认 from 地址有足够的代币和 gas
  3. 研究表明将所有十六进制更改为数字,例如 gasgasLimitvaluechainId

希望对react-native开发的其他人有所帮助,强烈推荐react-nativeweb3@1.0.0-beta.34,更稳定。由于一些 私钥 问题解决了这个问题,但是 web3 给出了错误 Error: Returned error: insufficient funds for gas * price + value ,如果想要深度调试实际上没有帮助,与 gas, price or value。小心