trufflesuite / truffle

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
14.02k stars 2.31k forks source link

Error: sender doesn't have enough funds to send tx. #4645

Closed LiuZhongHaoCN closed 2 years ago

LiuZhongHaoCN commented 2 years ago

Migrations dry-run (simulation)

Network name: 'mainnet-fork' Network id: 1 Block gas limit: 30087828 (0x1cb1a94)

1_initial_migration.js

Deploying 'Migrations'

block number: 14066980 block timestamp: 1643009346 account: *** balance: 0.496162978371760148 gas used: 233842 (0x39172) gas price: 70 gwei value sent: 0 ETH total cost: 0.01636894 ETH


Total cost: 0.01636894 ETH

2_deploy_contracts.js

Deploying '***'

block number: 14066982 block timestamp: 1643009367 account: *** balance: 0.125708628371760148 gas used: 5264692 (0x505534) gas price: 70 gwei value sent: 0 ETH total cost: 0.36852844 ETH

Error: sender doesn't have enough funds to send tx. The upfront cost is: 371000000000000000 and the sender's account only has: 125708628371760148

According to the simulation result, we can see I have enough balance to deploy my contract on mainnet, why the tuffle compares the upfront cost with the balance that has subtracted the upfront cost and return the error

eggplantzzz commented 2 years ago

From the logs you provided it looks like you do not have enough funds for your second migrations (2_deploying_contracts.js). The total cost is 0.36... and your balance is 0.12.... Try using an account with a higher balance.

LiuZhongHaoCN commented 2 years ago

Yes, you are right, but I think there is a bug in ruffle. The total cost of deploying is 0.37... and my acount has about 0.5125 to deploy the contract. The balance shows in log, I think is the remain value which has cost the gas. As we can see, when the simulation finished, the balance has 0.125... and the simulation shuld successes. However, why the tuffle compares the remain balance with the total cost again? Obviously, It will return an error, which is nonsense.

eggplantzzz commented 2 years ago

If you think there is a bug, could you please provide a repo and specific steps to reproduce this error? Are you deploying from the same account? If you could provide the repo and steps it would help me in troubleshooting this.

LiuZhongHaoCN commented 2 years ago

Emmm, it may not a bug. Yesterday, I used the MetaMask to mint an NFT, I also meet the funds is not enough. So, I have a question. Is there a security strategy in Ethereum that if we want to make a transaction, we must satisfy the funds > 2 * costs and the transaction will be executed.

eggplantzzz commented 2 years ago

It seems like you are basically asking for a strategy for very accurately calculating gas costs? I'm not too much of an expert on this kind of thing but maybe someone else might have some suggestions here?

eggplantzzz commented 2 years ago

Currently on mainnet it is impossible to predict the cost of a transaction because the base fee changes per block. Your best bet right now is to get a crude estimate of what it will all cost and pad your account, sorry :( Closing for issue maintenance!