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

  gas: 1,
  gasPrice: 1
}, privateKey)
.then((res) => {

  web3.eth.sendSignedTransaction(res.rawTransaction, function(err, hash) {
    if (err)

  • try to specify the account sending the transaction, and see if it works – Kaki Master Of Time Mar 7 '18 at 10:40
  • Specifying it where? – RaphArbuz Mar 7 '18 at 11:04
  • where you aded the gas and gasPrice attributes – Kaki Master Of Time Mar 8 '18 at 7:43
  • It's not helping unfortunately. And it looks like the signTransaction method is not expecting any 'from' field (web3js.readthedocs.io/en/1.0/…). Many thanks for trying though. – RaphArbuz Mar 8 '18 at 8:06
  • Did you ever get this sorted? I'm running into the same issue without any luck so far. – derekn Jun 1 '18 at 19:39

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)


I also had the same error. I was able to solve it by changing the mnemonic in my truffle-config.js to match the mnemonic given by Ganache CLI.

Because each time you run Ganache, the mnemonic changes. but you have to remember to change it in your config file to access the funds in the correct account

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.