using web3@1.0.0-beta.33
and react-native@0.59.10
, because latest web3
have install issue on react-native
, after deep research 1.0.0-beta.33
is suitable on 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);
});
}
web3@1.2.1
gas
, gasLimit
, value
and chainId
Hope help other who develop in react-native
, I highly recommend web3@1.0.0-beta.34
for react-native
, it more stable. This problem is solved due to some private key issue , but web3
is giving the error Error: Returned error: insufficient funds for gas * price + value
, actually not helping if want to deep debug, nothing about gas, price or value
. Be careful