I have already scrolled through similar questions, but the solutions provided didn't work.
As per title, I get the error insufficient funds for gas * price + value
BACKGROUND:
I am creating a webapp for a smart contract token. Once a user signs up, a new wallet is created for him in geth keystore using web3.personal.newAccount()
As the newly generated address is retrieved, the miner sends 777 ETHER to this new adddress with web3.eth.sendTransaction()
in order to be able to execute transactions. Afterwards, this new address sends a transaction to the smart contract contractDeployed.createWallet()
. This is the transaction where sometimes I get the error insufficient funds for gas * price + value
. It doesn't always happen, but 20% of the time is quite noticeable.
I can't get my head around it as I have set on the miner --gasprice "1"
and all transactions are executed with predefined gasLimit and gasPrice (as shown in the attached code).
I have tried to nest the web3js calls with callbacks and with batch, no changes. I think I am waiting for the confirmation of the previous transaction before sending the new one.
Notes: I am using web3 0.20.6
CODE:
// Initialization Skipped
const bank = "0x49b36fa1772bdb4d9249f43179832ccdb3732ffc";
const defaultGasPrice = web3.toHex(4);
const defaultGasLimit = 3700000;
const topUpWei = 777;
// Sign up
router.post('/api/v1/address', function(req, res){
const data = { name: req.body.name.replace(" ", ""), passphrase: req.body.passphrase };
let address;
return Promise.resolve()
.then(function() {
address = web3.personal.newAccount(data.passphrase);
})
.then(function() {
return web3.personal.unlockAccount(bank, "");
})
.then(function(ret) {
if (ret) {
return web3.eth.sendTransaction({ from: bank, to: address, value: topUpWei, gas: defaultGasLimit, gasPrice: defaultGasPrice });
}
throw ({ message: 'unable to decrypt mint wallet' });
})
.then(function(ret) {
if (ret) {
return web3.personal.unlockAccount(address, data.passphrase);
}
throw ({ message: 'unable to send initial Ethers' });
})
.then(function(ret) {
if (ret) {
return contractDeployed.createWallet(data.name, 2, { from: address, gas: defaultGasLimit, gasPrice: defaultGasPrice });
}
throw ({ message: 'unable to decrypt ' + data.name + ' wallet' });
})
.then(function(ret) {
if (!ret) {
throw ({ message: 'unable to create wallet ' + data.name });
}
})
.then(function() {
return res.status(200).json({ address: address });
})
.catch(function(err) {
console.log(err.message);
return res.status(500).json({error: err.message});
});
return Promise.resolve(null);
});
module.exports = router;