0

I'm new to Solidity. My contract tries to receive the Chainlink ERC20 token on Rinkeby testnet from a users address.

First transaction: user gives approval. This goes through.

Second transaction: user calls contract function to pull the token. This fails by error "execution reverted".

// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;

interface IERC20 { 
   function approve(address spender, uint256 amount) external returns (bool);
   function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}

contract theContract {
    
    //Chainlink Contract Address on Rinkeby
    IERC20 myToken = IERC20(0x01BE23585060835E02B77ef475b0Cc51aA1e0709);
    
    function askForApproval(uint256 amount) public payable returns (bool) {
        return myToken.approve(address(this), amount);
    }

    function pullToken(uint256 amount) public payable returns (bool) {
        return myToken.transferFrom(msg.sender, address(this), amount);
    }
}

I kind of gave up on this. Would be very glad if someone can give me a hint. Thanks

4
  • What does askForApproval
    – Majd TL
    Nov 12, 2021 at 17:28
  • The user should approve the tokens using directly the original contract and not ur contract
    – Majd TL
    Nov 12, 2021 at 17:29
  • Hi @Majd TL, what do you mean by original contract?
    – hereyraa
    Nov 12, 2021 at 23:55
  • the user should call the approve function in 0x01BE23585060835E02B77ef475b0Cc51aA1e0709 directly and not through your contract.
    – Majd TL
    Nov 13, 2021 at 7:41

0

Browse other questions tagged or ask your own question.