I'm trying to run the javascript following code to make a transaction to a contract function offline against a Ganache blockchain but I get the following error:
"Error: Returned error: sender doesn't have enough funds to send tx. The upfront cost is: 1 and the sender's account only has: 0"
(privateKey and publicKey are a Ganache account public/private keys).
I don't know why the script cannot figure out the sender account balance. Any idea?
Many thanks.
var myContract = new web3.eth.Contract(abi, contractAddress, {
from: publicKey,
});
var data = myContract.methods.pickWinner().encodeABI();
web3.eth.accounts.signTransaction({
data,
gas: 1,
gasPrice: 1
}, privateKey)
.then((res) => {
web3.eth.sendSignedTransaction(res.rawTransaction, function(err, hash) {
if (err)
console.log(err);
else
console.log(hash);
});
});
Best Answer
There was a known issue pertaining sendRawTransaction and ganache-cli v6.1.5. Upgrading to v6.1.6 should fix your issue. If you're using the GUI then upgrade to 1.2.1 which contains the aforementioned fix (https://github.com/trufflesuite/ganache/releases/tag/v1.2.1)