1

I'm trying to deploy a simple test contract in Remix. However, the compiler does not like this method:

function _approveWeth(uint256 _amount) internal { IERC20(WETH).approve(ZRX_STAKING_PROXY, _amount); } 

And throws a:

creation of ctr errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.

Whenever I try to deploy this contract:

pragma solidity ^0.5.0; pragma experimental ABIEncoderV2; interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function allowance(address owner, address spender) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } contract ctr { // Addresses address payable OWNER; address ZRX_STAKING_PROXY = 0xa26e80e7Dea86279c6d778D702Cc413E6CFfA777; // Fee collector address WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; address SAI = 0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359; address DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F; constructor() public payable { _getWeth(msg.value); _approveWeth(msg.value); OWNER = msg.sender; } function _getWeth(uint256 _amount) internal { (bool success, ) = WETH.call.value(_amount)(""); require(success, "failed to get weth"); } function _approveWeth(uint256 _amount) internal { IERC20(WETH).approve(ZRX_STAKING_PROXY, _amount); } } 

I've tried even changing _approveWeth to be public payable thinking that was the reason, but I still get the error until I completely comment out my invocation of the method (then I can deploy). Compiled with 0.5.17.

1 Answer 1

1

The problem is that you are using the WETH mainnet address in a smart contract that you are trying to deploy, I understand, on the Remix javaScript VM environment, a private local blockchain used for testing. Since the address 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 is not a smart contract on the test network, the call to approve fails in the _approveWeth function.

What you can do to successfully deploy and test your ctr smart contract:

  1. Deploy the WETH smart contract on the test network

The code can be found here : https://etherscan.io/address/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2#code.

  1. Get the WETH address

You should see on Remix, in the "Deployed Contracts" section, an icon to the right of the contract address to copy it.

  1. In the ctr contract, replace 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 with the address you obtained.

  2. Deploy ctr : it should work.

Then you can do the same for SAI, DAI and ZRX_STAKING_PROXY smart contracts.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.