When I try to make a deposit, Ethereum is transferred but the Wrapped ether is not received. Here is my code
interface IWETH is IERC20 {
receive() external payable;
function deposit() external payable;
function withdraw(uint256 wad) external;
}
contract Swap {
address payable private constant WETH =
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
function wrapEther() external payable {
uint256 ETHAmount = msg.value;
//create WETH from ETH
if (msg.value != 0) {
IWETH(WETH).deposit{ value: ETHAmount }();
}
require(
IWETH(WETH).balanceOf(address(this)) >= ETHAmount,
"Ethereum not deposited"
);
}
function unwrapEther(uint256 Amount) external {
address payable sender = msg.sender;
if (Amount != 0) {
IWETH(WETH).withdraw(Amount);
sender.transfer(address(this).balance);
}
}
}
hard-hat config
import "@nomicfoundation/hardhat-toolbox";
import "hardhat-contract-sizer";
const config = {
defaultNetwork: "ganache",
solidity: "0.7.6",
paths: {
artifacts: "./src/artifects",
},
networks: {
ganache: {
allowUnlimitedContractSize: true,
url: "http://127.0.0.1:8545",
},
},
settings: {
optimizer: {
enabled: true,
runs: 1,
},
},
};
export default config;
here is the error after unwrapEther
function is being called
Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Internal JSON-RPC error.
{
"message": "VM Exception while processing transaction: revert",
"code": -32000,
"data": {
"stack": "c: VM Exception while processing transaction: revert\n at Function.c.fromResults