trufflesuite / ganache

: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
2.61k stars 676 forks source link

Zero balance in funded wallets #4404

Open Kevin-Mok opened 1 year ago

Kevin-Mok commented 1 year ago

When I launch Ganache with ganache --wallet.accounts 0xe8ee08a685d093206043f7274958f3a51944ce0b49393d20fd9fed2d0585077b,50000000000000000000, I see:

ganache v7.8.0 (@ganache/cli: 0.9.0, @ganache/core: 0.9.0)
Starting RPC server

Available Accounts
==================
(0) 0x4f2D6eB43A905aE40D1921188ae41d213660Cb40 (50 ETH)

Private Keys
==================
(0) 
0xe8ee08a685d093206043f7274958f3a51944ce0b49393d20fd9fed2d0585077b

But when I do web3.eth.getBalance(0x4f2D6eB43A905aE40D1921188ae41d213660Cb40) in my code, this returns 0, and I cannot send any transactions. Why is this happening? You can run my code here on the balance branch.

Kevin-Mok commented 1 year ago

I'm actually using:

const privateKey = "0xe8ee08a685d093206043f7274958f3a51944ce0b49393d20fd9fed2d0585077b";
const account = web3.eth.accounts.privateKeyToAccount(privateKey);
const balance = await web3.eth.getBalance(account.address);
jehtee commented 1 year ago

I am having what seems to be the same problem. I airdrop test tokens to an account. I can query for those tokens in console and they show. But my test script that queries all 10 accounts for their test token balances all show 0 tokens.

Ganache > Contracts tab show this error:

⚠ Your Truffle Project can no longer be found. Did you delete or move it? Update the location or restart Ganache.

Even though the location is correct.

davidmurdoch commented 1 year ago

@Kevin-Mok that branch works for me:

ganache output:

~/code/test/ganache-tx (balance) $ ganache --wallet.accounts   0xe8ee08a685d093206043f7274958f3a51944ce0b49393d20fd9fed2d0585077b,50000000000000000000 
ganache v7.8.0 (@ganache/cli: 0.9.0, @ganache/core: 0.9.0)
Starting RPC server

Available Accounts
==================
(0) 0x4f2D6eB43A905aE40D1921188ae41d213660Cb40 (50 ETH)

Private Keys
==================
(0) 0xe8ee08a685d093206043f7274958f3a51944ce0b49393d20fd9fed2d0585077b

# ... skipped for brevity

RPC Listening on 127.0.0.1:8545
eth_getTransactionCount
eth_getBalance
eth_sendRawTransaction

  Transaction: 0xb0daad64327105d82c3ea8aba95011fccbe41fb4522033bdbfea86ab51a1e819
  Gas usage: 21000
  Block number: 1
  Block time: Wed May 17 2023 12:09:18 GMT-0400 (Eastern Daylight Time)

eth_getTransactionReceipt

code ouput:

~/code/test/ganache-tx (balance) $ node index.js 
0x4f2D6eB43A905aE40D1921188ae41d213660Cb40
50000000000000000000
Creating transaction...
Signing transaction...
Serializing transaction...
Sending transaction...
tx transactionHash: 0xb0daad64327105d82c3ea8aba95011fccbe41fb4522033bdbfea86ab51a1e819

@jehtee, your issue seems to be for Ganache UI.

nagualdev commented 1 year ago

I have the same problem, launching ganache as follows:

ganache-cli --fork https://eth-mainnet.alchemyapi.io/v2/ --networkId 1 --db c:/tmp/ganache-db/ --mnemonic "scare hope major aspect clock input dial anchor whale catalog bachelor nice"

When calling eth_getBalance(), ganache allways returns 0.

davidmurdoch commented 1 year ago

@nagualdev if the db exists new accounts aren't refunded. https://github.com/trufflesuite/ganache/issues/1030 is that your issue?

nagualdev commented 1 year ago

@davidmurdoch when I launch it, I can see the list of accounts with their balances (100ETH) in the console. However if I invoke eth_getBalance() using web3 library for any of these accounts, it allways returns 0.

davidmurdoch commented 1 year ago

@nagualdev I believe that's related to the bug in #1030. If the start up mnemonic/seed/accounts have changed since the DB was created it lies to you about their account balance on start up. It's a very annoying bug and I'm sorry it exists :-(

SvenMeyer commented 1 year ago

I have the same problem with Ganache GUI.

I am pretty sure that worked 2 years ago ;-)

UPDATE Workaround : Do not use the Quickstart but instead create a new workspace, provide a mnemonic of your choice, then start

davidmurdoch commented 1 year ago

@SvenMeyer can you open an issue on Ganache UI for this? What you are describing is a slightly different bug.

BarneyChambers commented 10 months ago

I am having a similar issue on ganache-cli. It seems like my wallets are funded until I run any transaction, then all the funded wallets lose their 100ETH

marcello33 commented 7 months ago

Similar issue here.

I launch it with

ganache \
  --chain.hardfork istanbul \
  --miner.blockTime 1 \
  --database.dbPath $DATA_DIR \
  --wallet.accounts  "0x9c08ba1e42bfdd34a017a4bcbf4c92b60e7a497f27534fdb1ac4272c5231d973, 1000000000000000000000"  "0x10efc825120aedaa0d7ba3d77a6ec068b63c1893e38f995ee528410a67f8e7a0, 1000000000000000000000"  "0x70529f30cf0444a66590625f13e4138ef67a754fd53a58defebfb38f638d5780, 1000000000000000000000"  \
  --miner.blockGasLimit 8000000 \
  --miner.defaultGasPrice 0x1 \
  --chain.allowUnlimitedContractSize true \
  --server.port 9545 \
  --server.host 0.0.0.0

Initial output looks correct

Dec 06 16:10:35 ip-10-0-0-181 systemd[1]: Started ganache.
Dec 06 16:10:35 ip-10-0-0-181 bash[29664]: + DATA_DIR=/home/ubuntu/matic-cli/devnet/data/ganache-db
Dec 06 16:10:35 ip-10-0-0-181 bash[29664]: + ganache --chain.hardfork istanbul --miner.blockTime 1 --database.dbPath /home/ubuntu/matic-cli/devnet/data/ganache-db --wallet.accounts '0x9c08ba1e42bfdd34a017a4bcbf4c92b60e7a497f27>
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: ganache v7.9.1 (@ganache/cli: 0.10.1, @ganache/core: 0.10.1)
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: Starting RPC server
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: Available Accounts
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: ==================
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: (0) 0xaE7bF1d17021F959c238aC3029cF4019d3128944 (1000 ETH)
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: (1) 0xaBf299c699EEcBE1ecc08d25a1836CB677fED93F (1000 ETH)
Dec 06 16:10:35 ip-10-0-0-181 systemd[1]: Started ganache.
Dec 06 16:10:35 ip-10-0-0-181 bash[29664]: + DATA_DIR=/home/ubuntu/matic-cli/devnet/data/ganache-db
Dec 06 16:10:35 ip-10-0-0-181 bash[29664]: + ganache --chain.hardfork istanbul --miner.blockTime 1 --database.dbPath /home/ubuntu/matic-cli/devnet/data/ganache-db --wallet.accounts '0x9c08ba1e42bfdd34a017a4bcbf4c92b60e7a497f27>
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: ganache v7.9.1 (@ganache/cli: 0.10.1, @ganache/core: 0.10.1)
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: Starting RPC server
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: Available Accounts
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: ==================
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: (0) 0xaE7bF1d17021F959c238aC3029cF4019d3128944 (1000 ETH)
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: (1) 0xaBf299c699EEcBE1ecc08d25a1836CB677fED93F (1000 ETH)
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: (2) 0xCD612A62C144BaFF8F3A76b499Ccf4F78c94bf0D (1000 ETH)
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: Private Keys
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: ==================
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: (0) 0x9c08ba1e42bfdd34a017a4bcbf4c92b60e7a497f27534fdb1ac4272c5231d973
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: (1) 0x10efc825120aedaa0d7ba3d77a6ec068b63c1893e38f995ee528410a67f8e7a0
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: (2) 0x70529f30cf0444a66590625f13e4138ef67a754fd53a58defebfb38f638d5780
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: Default Gas Price
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: ==================
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: 1
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: BlockGas Limit
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: ==================
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: 8000000
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: Call Gas Limit
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: ==================
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: 50000000
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: Chain
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: ==================
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: Hardfork: istanbul
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: Id:       1337
Dec 06 16:10:35 ip-10-0-0-181 bash[29665]: RPC Listening on 0.0.0.0:9545

After a while tho, all accounts (except the first one) report a balance of 0 ETH First account > correct!

curl http://localhost:9545   -X POST   -H "Content-Type: application/json"   --data '{"method":"eth_getBalance","params":["0xaE7bF1d17021F959c238aC3029cF4019d3128944", "latest"],"id":1,"jsonrpc":"2.0"}'
{"id":1,"jsonrpc":"2.0","result":"0xffffffffffffffffffffffffffffffda784b6386338c4"}

Second account > 0?!

curl http://localhost:9545   -X POST   -H "Content-Type: application/json"   --data '{"method":"eth_getBalance","params":["0xaBf299c699EEcBE1ecc08d25a1836CB677fED93F", "latest"],"id":1,"jsonrpc":"2.0"}'
{"id":1,"jsonrpc":"2.0","result":"0x0"}

Third account > 0?!

curl http://localhost:9545   -X POST   -H "Content-Type: application/json"   --data '{"method":"eth_getBalance","params":["0xCD612A62C144BaFF8F3A76b499Ccf4F78c94bf0D", "latest"],"id":1,"jsonrpc":"2.0"}'
{"id":1,"jsonrpc":"2.0","result":"0x0"}

Is this guys something you'll be fixing? Is there a version (even old one) not affected by this issue?

Thanks

davidmurdoch commented 7 months ago

@marcello33 Looks like you have a db but changed mnemonics and other start up params. This doesn't work. See: https://github.com/trufflesuite/ganache/issues/756

But no, Consensys doesn't maintain Ganache anymore (no one does) and won't be fixing it.