My code is:
function sendEth(fromAddress, secret, toAddress, amount) {
let params = {
to: toAddress,
from: fromAddress,
value: web3.utils.toWei(amount + '', 'ether')
};
console.log(params);
return Promise.all([web3.eth.estimateGas(params), web3.eth.getGasPrice()])
.then((response) => {
const estimatedGas = response[0];
const gasPrice = response[1];
params.gas = estimatedGas;
params.gasPrice = web3.utils.toWei(1.1 * gasPrice + ''); // Use 10% more gas than recommended
params.value = web3.utils.toWei(params.value - params.gas * params.gasPrice + '');
return web3.eth.accounts.signTransaction(params, secret);
})
.then((signedTx) => {
return web3.eth.sendSignedTransaction(signedTx.rawTransaction);
});
}
But I get an error:
Error: while converting number to string, invalid number value '-1.1549989999999999e+23', should be a number matching (^-?[0-9.]+).