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);
});
});