I need your help! I run a hardhat testnet on localhost in a fork goerli mode and would like to test a simple Ether to WETH wrap and unwrap.
I use WETH contract address 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 and copied the ABI.
First, I initialize a contract object:
const wethContract = new ethers.Contract( wethAddress, wethABI, owner ); Now I can use the deposit and withdraw functions successfully:
const testSwap = await wethContract.deposit({ value: ethers.utils.parseEther("1"), }); Checking the ETH balance before and after this swap, I can assume that it works and also the terminal shows the transaction:
eth_sendTransaction Transaction: 0x9431f941bdd23074850ecd7cc9d0c2c8e93001d115e11205f5a38c934376ffbe From: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 To: 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 Value: 1 ETH Gas used: 21064 of 21065 Block #8521084: 0x295a494348ab2921220fc8dd693108e617e1444c8015448fd135014da6e3164c Now I simply want to check the WETH balance of my account:
const wethBalanceBeforeWrap = await wethContract.balanceOf(owner.address); This does not work but gives me a "Calling an account which is not a contract" error
eth_call WARNING: Calling an account which is not a contract From: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 To: 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 I figured out that all Read functions of the WETH Contract give me this error while I can simply use the Write functions. This is very weird to me - any idea what I'm doing wrong?