I'm trying to do Escrow.sol
with ERC20 token. When I deploy the Escrow.sol on Remix and wanna deposit 10 tokens, it appears The called function should be payable if you send value and the value you send should be less than your current balance.
So did the function of withdraw.
How can I fix it?
the following is my erc20.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
constructor() ERC20("GINWEI", "GW") public payable {
_mint(msg.sender, 1000);
}
}
and the following is escrow.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
import "./erc20.sol";
contract MyEscrow {
mapping(address => mapping(address => uint256)) public _deposits;
address payable payee = payable(msg.sender);
MyToken token;
function deposit(uint256 amount) public payable {
token.approve(address(this), amount);
token.transfer(address(this), amount);
_deposits[payee][address(token)] += amount;
}
function depositsOf() public view returns (uint256) {
return _deposits[payee][address(token)];
}
function withdraw(uint256 payment) public payable {
_deposits[payee][address(token)] -= payment;
payee.transfer(payment);
}
}