【问题标题】:web3 on react-native : Error: Returned error: insufficient funds for gas * price + valuereact-native 上的 web3:错误:返回错误:gas 资金不足 * 价格 + 价值
【发布时间】:2019-12-29 15:13:06
【问题描述】:

使用web3@1.0.0-beta.33和react-native@0.59.10,因为最新的web3在react-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地址有足够的token和gas
  3. 研究表明将所有十六进制更改为数字,例如gas、gasLimit、value 和chainId

【问题讨论】:

    标签: react-native web3js


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2021-05-13
      • 2018-04-30
      • 2017-08-15
      • 2018-05-03
      • 2018-03-20
      • 1970-01-01
      • 1970-01-01
      • 2020-05-25
      • 1970-01-01
      相关资源
      最近更新 更多