Out of the blue, I started having issues with running my unit tests with Truffle. Now when I run truffle test I see the following error message:
truffle test
Using network 'test'.
Error: sender doesn't have enough funds to send tx. The upfront cost is: 672197500000000000 and the sender's account only has: 645096100000000000
at Object.InvalidResponse (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1)
at /usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:86:1
at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-migrate/index.js:225:1
at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-provider/wrapper.js:134:1
at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1)
at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1)
at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1)
at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1)
at IncomingMessage.emit (events.js:185:15)
at endReadableNT (_stream_readable.js:1106:12)
at process._tickCallback (internal/process/next_tick.js:114:19)
Few things that puzzle me here:
672197500000000000 is 0.6721975 ether! This seems like too much for a small contract with an empty constructor645096100000000000I guess that Truffle keeps a state (per project?) between executions and now it prevents tests execution.
Is there any way I can fix this?
I've restarted my machine, and now all tests are passing.
This is still an odd behavior though.
@mushketyk Thanks, for reporting. A few questions:
truffle develop?test network in truffle.js? It would be nice to have simple reproduction steps for this although from your description it seems like it might difficult to get those . . .
Hi @cgewecke
I am having the same issue.
underTest:
pragma solidity ^0.4.24;
contract myContract{
address owner;
uint balance;
constructor() public payable {
owner = msg.sender;
balance = msg.value;
}
function() public payable{
balance += msg.value;
}
}
test suite:
pragma solidity ^0.4.24;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/MyContract.sol";
contract TestMyContract {
MyContract public underTest;
uint public initialBalance = 100 ether;
function beforeEach() public{
underTest = MyContract(DeployedAddresses.MyContract());
}
function testIsPayable() public {
address(underTest).transfer(1 wei);
}
}
Also seems my error is happending before the test cases are called:
"before all" hook: prepare suite:
Error: sender doesn't have enough funds to send tx. The upfront cost is: 100672197500000000000 and the sender's account only has: 99295519300000000000
at Object.InvalidResponse (/home/daithi/.nvm/versions/node/v9.2.1/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1)
at /home/daithi/.nvm/versions/node/v9.2.1/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:86:1
at /home/daithi/.nvm/versions/node/v9.2.1/lib/node_modules/truffle/build/webpack:/packages/truffle-provider/wrapper.js:134:1
at XMLHttpRequest.request.onreadystatechange (/home/daithi/.nvm/versions/node/v9.2.1/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1)
at XMLHttpRequestEventTarget.dispatchEvent (/home/daithi/.nvm/versions/node/v9.2.1/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1)
at XMLHttpRequest._setReadyState (/home/daithi/.nvm/versions/node/v9.2.1/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1)
at XMLHttpRequest._onHttpResponseEnd (/home/daithi/.nvm/versions/node/v9.2.1/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1)
at IncomingMessage.<anonymous> (/home/daithi/.nvm/versions/node/v9.2.1/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1)
at endReadableNT (_stream_readable.js:1054:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
@mushketyk what version of Ganache CLI are you using? v6.1.5 introduced a similar error that got fixed in v6.1.6
@daithi-coombes same for you; are you using Ganache/ganache-cli in the loop? If so, Is it v6.1.5?
Using v6.1.6
Here's my stack:
Debian 9 Stretch
Ganache CLI v6.1.6 (ganache-core: 2.1.5)
Truffle v4.1.13
@daithi-coombes Does setting the initialBalance value lower fix this error? Ganache initializes accounts with 100 ether and the entire amount is being sent to the Solidity test for use within that context.
Ex:
uint public initialBalance = 50 ether;
@cgewecke solves my problem.
Each time for a test, you consume initialBalance out of initial 100 ETH of Ganache account. If you set initialBalance to be 100, the test only passes the first time and you will have no ethers next time to run another test.
Having a similar issue here when I run ganache-cli with --db for persistence.
The error is already on the Migrations contract, just running
truffle migrate --network localnet
Without --db it's going to be fine. Any hint?
Happens to me too. In my case the test i was running had an incorrect amount in the value of the transaction (a javascript number with decimals) that made the transaction cost a lot and throw the error.
Thank you for raising this issue! It has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you would like to keep this issue open, please respond with information about the current state of this problem.
There has been no new activity on this issue since it was marked as stale 7 days ago, so it is being automatically closed. If you'd like help with this or a different problem, please open a new issue. Thanks!
same error
Error: sender doesn't have enough funds to send tx. The upfront cost is: 1024628448149621997816844960494848980548232143211 and the sender's account only has: 99717527600000000000
To all who come here. There may be multiple causes to the error referenced on this thread but in my case it had to do with passing values to the Web3JS functions that were not all Big Numbers. If you are having this error and are not already converting all gas related values to a Big Number, give that a try using the toBN() function found in the web3-utils package. This may also clean up a host of other odd error messages you may see intermittently, even seemingly unrelated errors like intermittent "Internal JSON RPC response" error.
Thanks for your response! This issue is no longer considered stale and someone from the Truffle team will try to respond as soon as they can.
Next steps here seem to involve figuring out what is actionable. Maybe improve problem detection and messaging?
Thank you for raising this issue! It has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you would like to keep this issue open, please respond with information about the current state of this problem.
There has been no new activity on this issue since it was marked as stale 7 days ago, so it is being automatically closed. If you'd like help with this or a different problem, please open a new issue. Thanks!
Hello everyone, it's 2020 and I got the same problem :)
I'm using Ganache CLI v6.9.0.
The error says: sender doesn't have enough funds to send tx. The upfront cost is: 672197500000000000 and the sender's account only has: 0
Anyone help?
I was able to solve it by changing the mnemonic in my truffle-config.js to match the mnemonic given by Ganache CLI
Oh, well, back to closed, then :)
Thanks @abuaesh
changing the mnemonic in my truffle-config.js to match the mnemonic given by Ganache CLI
Hello. Can you explain how you did that? I have looked up documentation on truffle configuration and couldn't find much information on how to specify the mnemonic in truffle-config.js. It looks like it can only be specified if you define n HDWalletProvider. Is that correct? Thanks.
changing the mnemonic in my truffle-config.js to match the mnemonic given by Ganache CLI
Hello. Can you explain how you did that? I have looked up documentation on truffle configuration and couldn't find much information on how to specify the mnemonic in truffle-config.js. It looks like it can only be specified if you define n HDWalletProvider. Is that correct? Thanks.
Sure @hswopeams 馃憤Here are the steps:
new HDWalletProvider(paste_the_mnemonic_here, "http://127.0.0.1:8545/", 0, 10)
var HDWalletProvider = require("truffle-hdwallet-provider");
var mnemonic = "Get this text from the mneumonic in your Ganache CLI - they are 12 words- also to the seed to your wallet";
module.exports = {
networks: {
development: {
provider: function() {
return new HDWalletProvider(mnemonic, "http://127.0.0.1:8545/", 0, 10);
},
network_id: '*',
gas: 9999999
}
},
compilers: {
solc: {
version: "^0.4.25" //the version of solidity used in writing your contract
}
}
};
Hope this helps, good luck!
Thanks! I'll give it a try.
Most helpful comment
Sure @hswopeams 馃憤Here are the steps:
new HDWalletProvider(paste_the_mnemonic_here, "http://127.0.0.1:8545/", 0, 10)Note: if your truffle-config.js file does not have module.exports set, or you are starting the file from scratch, consider adding following code to it:
Hope this helps, good luck!