All pre-funded address balances drop to 0 after running a transaction
BarneyChambers opened this issue · comments
I am running a forked instance of Arbitrum using ganache like so:
ganache-cli --fork https://arb-mainnet.g.alchemy.com/v2/MYAPIKEY --db ./ganache-data -h 0.0.0.0 --chainId 42161 --mnemonic "my cool mnemonic"
I receive my prefunded wallets each with 100 ETH, but when I run any smart contracts on my forked instance, afterwards all of my ether balances on my funded accounts drop to 0.
Is this intended behavior or a bug?
There is a bug when starting with an existing --db
. It doesn't validate that the start up params given match the ones that created the db in the first place, the mnemonic you are giving it is likely different than the mnemonic that was given when the db was first initialized.
Another perspective of this bug: ganache should re-fund the mnemonic's accounts with 100 eth every time it starts up, but doesn't.
That's probably what is happening here.
Here is the issue: #1030
Thank you. I have rm -rf ./ganache-data
but I am still having the issue. Are there any other config files etc I might need to try deleting to reset my ganache back to default?
What version of ganache?
Ganache CLI v6.12.2 (ganache-core: 2.13.2)
Oh. Uninstall that. It's deprecated. Install ganache via npm install ganache -g
Thanks, I updated to latest using npm install ganache -g
and it seems that I am still having the issue after I delete my db folder, and make a fresh instance of my blockchain, after running a couple of scripts, it seems that my funded balances all go to 0
I am now using ganache v7.9.0 (@ganache/cli: 0.10.0, @ganache/core: 0.10.0)
Can you paste the ganache output?
ubuntu@ip-172-31-19-56:~$ ganache --fork https://arb-mainnet.g.alchemy.com/v2/xxxxxxxxxxxxxxx --db ./ganache-data -h 0.0.0.0 --chain.chainId 42161 --mnemonic "xxxxxxxxxxxx" --accounts=10
ganache v7.9.0 (@ganache/cli: 0.10.0, @ganache/core: 0.10.0)
Starting RPC server
eth_blockNumber
Available Accounts
(0) 0x828ad78d7F05A0EA9E6c2e6f50B4C8a38D0229A8 (1000 ETH)
(1) 0x65Ec566142e97603Aa785A8C0C25A7C1303ae6c6 (1000 ETH)
(2) 0xe9c6FB81bDCf8c19CEa349b465e1034545A0f381 (1000 ETH)
(3) 0x80Ab02e017A7b1d27b64F2C0C7fC539D162F572a (1000 ETH)
(4) 0x7Dfd66650F3D4121Db002Df0958B21678C3e398a (1000 ETH)
(5) 0x10bd3Bf0Df6C5E256793976515103f452e237AcE (1000 ETH)
(6) 0x0432b9f8CfF2e7B321ad91e6F6d258c0010cbA5F (1000 ETH)
(7) 0xa7F4088D3f5A72B7dBE18Fd649a283ea7CD3a0b3 (1000 ETH)
(8) 0x716f034B9D588A7073d44Da7c4401dAc9f2Cf848 (1000 ETH)
(9) 0x9E00D0F6F27684673FAC974E38BDE71986BC0A3d (1000 ETH)
Private Keys
(0) xxxxxxxxxxxx
(1) xxxxxxxxxxxx
(2) xxxxxxxxxxxx
(3) xxxxxxxxxxxx
(4) xxxxxxxxxxxx
(5) xxxxxxxxxxxx
(6) xxxxxxxxxxxx
(7) xxxxxxxxxxxx
(8) xxxxxxxxxxxx
(9) xxxxxxxxxxxx
HD Wallet
Mnemonic: xxxxxxxxxxxx
Base HD Path: m/44'/60'/0'/0/{account_index}
Default Gas Price
2000000000
BlockGas Limit
30000000
Call Gas Limit
50000000
Forked Chain
Location: https://arb-mainnet.g.alchemy.com/v2/xxxxxxxxxxxxxxxxxxxxxxxxx
Block: 123893240
Network ID: 42161
Time: Tue Aug 22 2023 14:54:20 GMT+0000 (Coordinated Universal Time)
Chain
Hardfork: shanghai
Id: 42161
RPC Listening on 0.0.0.0:8545
eth_call
eth_blockNumber
eth_blockNumber
eth_blockNumber
eth_blockNumber
eth_blockNumber
eth_blockNumber
eth_blockNumber
eth_chainId
miner_stop
miner_setEtherbase
eth_blockNumber
eth_coinbase
miner_start
eth_accounts
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_blockNumber
eth_getBlockByNumber
eth_call
eth_blockNumber
eth_call
eth_call
eth_blockNumber
eth_blockNumber
eth_blockNumber
eth_call
eth_call
eth_blockNumber
eth_blockNumber
eth_blockNumber
eth_blockNumber
eth_chainId
miner_stop
miner_setEtherbase
eth_coinbase
miner_start
eth_accounts
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_accounts
eth_chainId
miner_stop
miner_setEtherbase
eth_coinbase
miner_start
eth_accounts
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_blockNumber
net_version
eth_chainId
miner_stop
miner_setEtherbase
eth_coinbase
miner_start
eth_accounts
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_blockNumber
net_version
net_version
eth_getBlockByNumber
Hm, it seems that no transactions are being sent here. Can you provide a reproduction script?
Sure, if I run these two scripts, afterwards I will lose my ETH in the funded accounts. For reference, I am using hardhat in typescript mode. The way to run these in hardhat is npx hardhat run scripts/theScriptYouWant --network arbitrumFork
where arbitrumFork
is one of the chains in my hardhat-config.ts
that points to my ganache instance:
wrapETH.ts
import { ethers } from "hardhat";
//import "@uniswap/v3-periphery";
const main = async () => {
const [owner, ...accounts] = await ethers.getSigners();
console.log("owner address: ", owner.address);
let WETHAddress = '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1';
//wrap 50 ETH into WETH
let WETH = new ethers.Contract(WETHAddress, ['function deposit() public payable'], owner);
let depositTx = await WETH.deposit({value: ethers.utils.parseEther('50')});
await depositTx.wait();
console.log(`Wrapped ETH!`);
};
main()
.then(() => process.exit(0))
.catch((error: Error) => {
console.error(error);
process.exit(1);
});
SwapETHForUSDC
import { ethers } from "hardhat";
//import "@uniswap/v3-periphery";
const main = async () => {
const [owner, ...accounts] = await ethers.getSigners();
console.log("owner address: ", owner.address);
//define uniswap v3 router
let uniswapV3RouterAddress = '0xe592427a0aece92de3edee1f18e0157c05861564';
let usdcAddress ='0xff970a61a04b1ca14834a43f5de4533ebddb5cc8';
let WETHAddress = '0x82af49447d8a07e3bd95bd0d56f35241523fbab1';
let ExactInputSingleParams = {
tokenIn: WETHAddress,
tokenOut: usdcAddress,
fee: 500,
recipient: owner.address,
deadline: 1913450590, //2030
amountIn: ethers.utils.parseEther('50'),
amountOutMinimum: 65000000000, //65k
sqrtPriceLimitX96: 0
}
console.log('approving...');
//approve uniswap v3 router to spend WETH
let WETH = new ethers.Contract(WETHAddress, ['function approve(address spender, uint256 amount) public returns (bool)'], owner);
let approveTx = await WETH.approve(uniswapV3RouterAddress, ethers.utils.parseEther('50'));
await approveTx.wait();
console.log('swapping...');
let uniswapV3Router = await ethers.getContractAt('ISwapRouter', uniswapV3RouterAddress);
let swapTx = await uniswapV3Router.exactInputSingle(ExactInputSingleParams);
await swapTx.wait();
console.log(`Swapped 50 ETH for USDC!`);
};
main()
.then(() => process.exit(0))
.catch((error: Error) => {
console.error(error);
process.exit(1);
});
I haven't run this yet, but are you sure your hardhat mnemonic matches your ganache mnemonic? And that the accounts they are using are the same (your logged "owner address"
should match the first account in ganache's list).
Yes I am 100% sure they are the same
I have made a video reproducing the issue:
And here are the logs for that video:
eth_blockNumber
eth_call
eth_call
eth_call
eth_blockNumber
eth_blockNumber
eth_call
eth_call
eth_blockNumber
eth_blockNumber
eth_blockNumber
eth_chainId
eth_chainId
eth_chainId
eth_accounts
eth_blockNumber
eth_chainId
eth_chainId
eth_estimateGas
eth_getBlockByNumber
eth_feeHistory
eth_sendTransaction
Transaction: 0xcfa2b7ee08f8bf7fa89df8db0cf974f9d070fae676976d48ea37ce73fcb5e323
Gas usage: 57975
Block number: 124132798
Block time: Wed Aug 23 2023 09:05:42 GMT+0000 (Coordinated Universal Time)
eth_chainId
eth_getTransactionByHash
eth_chainId
eth_getTransactionReceipt
eth_blockNumber
eth_blockNumber
eth_call
eth_call
eth_blockNumber
eth_chainId
miner_stop
miner_setEtherbase
eth_coinbase
eth_blockNumber
miner_start
eth_accounts
eth_getBalance
eth_estimateGas
eth_gasPrice
eth_sendTransaction
Transaction: 0xa436e2b5ab180af98abc1e6c53957640c2211787bf44e082f7f3cf0b0d118d1a
Gas usage: 21000
Block number: 124132800
Block time: Wed Aug 23 2023 09:06:36 GMT+0000 (Coordinated Universal Time)
eth_getBalance
eth_estimateGas
eth_gasPrice
eth_sendTransaction
Transaction: 0x0796e07d1d9213dd025b2016cb8098d441bf11f402bb92b98c89b866170ed240
Gas usage: 21000
Block number: 124132801
Block time: Wed Aug 23 2023 09:06:36 GMT+0000 (Coordinated Universal Time)
eth_getBalance
eth_estimateGas
eth_gasPrice
eth_sendTransaction
Transaction: 0x8cdebb09a8e1d5a7284c3f9197cedbc80ecfc54973528981db780ba536744bab
Gas usage: 21000
Block number: 124132802
Block time: Wed Aug 23 2023 09:06:37 GMT+0000 (Coordinated Universal Time)
eth_getBalance
eth_estimateGas
eth_gasPrice
eth_sendTransaction
Transaction: 0xd42eec6a8da4224a5b654460c5b9f6d6dae27827e294962694176c3d1ed0639a
Gas usage: 21000
Block number: 124132803
Block time: Wed Aug 23 2023 09:06:38 GMT+0000 (Coordinated Universal Time)
eth_getBalance
eth_estimateGas
eth_gasPrice
eth_sendTransaction
Transaction: 0xc728cfb42576482fc371e88fcfb05f3831d98de148fc8ae32616b57ae8c6ef8f
Gas usage: 21000
Block number: 124132804
Block time: Wed Aug 23 2023 09:06:38 GMT+0000 (Coordinated Universal Time)
eth_getBalance
eth_estimateGas
eth_gasPrice
eth_sendTransaction
Transaction: 0x9d3b6056be6552efb52d7061ec4f8c7dba420df3ad0872428d45ff310b1da8c3
Gas usage: 21000
Block number: 124132805
Block time: Wed Aug 23 2023 09:06:39 GMT+0000 (Coordinated Universal Time)
eth_getBalance
eth_estimateGas
eth_gasPrice
eth_sendTransaction
Transaction: 0xdcbdef431d0dba55495c08052ac838cbc3618fbea4e9ae6dac0cee22f39cacb3
Gas usage: 21000
Block number: 124132806
Block time: Wed Aug 23 2023 09:06:39 GMT+0000 (Coordinated Universal Time)
eth_getBalance
eth_estimateGas
eth_gasPrice
eth_sendTransaction
Transaction: 0x67cf3a94219538d61e43848ea64990a134ece082c1d33c58c50a8e2fd81ad817
Gas usage: 21000
Block number: 124132807
Block time: Wed Aug 23 2023 09:06:40 GMT+0000 (Coordinated Universal Time)
eth_getBalance
eth_estimateGas
eth_gasPrice
eth_sendTransaction
Transaction: 0x23d38d927415b28c38d49f495a1ec64a16782cc674ca86f8b06521bd3040843e
Gas usage: 21000
Block number: 124132808
Block time: Wed Aug 23 2023 09:06:41 GMT+0000 (Coordinated Universal Time)
eth_getBalance
eth_estimateGas
eth_gasPrice
eth_sendTransaction
Transaction: 0xdc7edc8887d4c8c14397c31a8b6ded31d4b02bb3094391730fa66e4e4f7dcd35
Gas usage: 21000
Block number: 124132809
Block time: Wed Aug 23 2023 09:06:41 GMT+0000 (Coordinated Universal Time)
eth_chainId
eth_chainId
eth_chainId
eth_accounts
eth_chainId
eth_blockNumber
eth_chainId
eth_estimateGas
eth_getBlockByNumber
eth_feeHistory
eth_sendTransaction
eth_blockNumber
eth_blockNumber
eth_call
eth_call
eth_call
eth_blockNumber
eth_call
eth_call
eth_blockNumber
eth_blockNumber
eth_blockNumber
eth_blockNumber
eth_blockNumber
eth_blockNumber
eth_blockNumber
eth_blockNumber
eth_blockNumber
There are 10 value transfer transactions in the logs above. I think something in your set up is draining the accounts. Try starting Ganache with --verbose
.
Thank you. I have
rm -rf ./ganache-data
but I am still having the issue. Are there any other config files etc I might need to try deleting to reset my ganache back to default?
Are you still having this issue or got it solved?
Yes I am 100% sure they are the same
Hi mate, are you still having this issue or got it solved? If not you can get intouch with me so we can both get it solved together because a lot of people have come with same complain and it work for them i believe we can solve this together...Don't exhitate to say hi
Thanks, I updated to latest using
npm install ganache -g
and it seems that I am still having the issue after I delete my db folder, and make a fresh instance of my blockchain, after running a couple of scripts, it seems that my funded balances all go to 0I am now using
ganache v7.9.0 (@ganache/cli: 0.10.0, @ganache/core: 0.10.0)
Hi mate, are you still having this issue or got it solved? If not you can get in touch with me so we can both get it solved together because a lot of people have come with same complain and it work for them i believe we can solve this together...Don't wait to say hi