0

I'm trying to implement contract which interacts with ERC-20 via interface. Code of interface was taken from openzeppelin github.

The problem is that it fails any transaction which triggers contract func.

What have I done wrong? :(

Example: Following func checks if sender has enough tokens of ERC-20 and sender allowed to spend tokens earlier. If conditions are success it transfers tokens from sender to custom contract address.

    function deposit(uint256 amount) public {
        require(tokenContract.balanceOf(msg.sender) >= amount, "Sender has not enough balance");
        require(tokenContract.allowance(msg.sender, address(this)) >= amount, "Contract is not allowed to transfer tokens");
        require(tokenContract.transferFrom(msg.sender, address(this), amount) == true, "Could not send tokens from the buyer");
    }

Extra info:

  • sender has enough tokens to spend
  • sender has approved custom contract before transaction

Failed transaction url: https://rinkeby.etherscan.io/tx/0x8df7513a0da10645ce3e300399e73bb58d28dcb8bddb92bddf40945751ae69fc

Sample contract code url: https://rinkeby.etherscan.io/address/0x479a28cff2194a67ccb95ddb960d09fcbb127462#code

ERC-20 (USDT) contract code url: https://rinkeby.etherscan.io/address/0x75cb130d6bbd3d915b34573dc3dd3fb45184f12f#code

0

That contract doesn't follow the final ERC20 specification.

The declaration for transferFrom doesn't return anything:

function transferFrom(address _from, address _to, uint _value) public;

The calling contract defines transferFrom returning a bool instead:

function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

OpenZeppelin provides the SafeERC20 library that is a wrapper that allows interacting with this type of contracts.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.