My goal is to build an abstract contract and send a specific erc20 token into it so that others can claim the erc20token with merkletree validations. However I am having problem approving the contract to spend this erc20. Here is my claiming function. Please help me figure out how to assign allowance or otherwise. Is there a walk-around to achieve the goal ?

function claimTokens(IERC20 _token, uint256 amount, bytes32[] calldata merkleProof) public {
        uint256 erc20balance = _token.balanceOf(address(this));
        require(amount <= erc20balance, "balance is low");
        bytes32 leaf = keccak256(abi.encodePacked(msg.sender, amount));
        bool valid = MerkleProof.verify(merkleProof, merkleRoot, leaf);
        require(valid, "Chimpz: Valid proof required.");
        require(!claimed[msg.sender], "Tokens already claimed.");
        claimed[msg.sender] = true;
        emit Claim(msg.sender, amount);
        _token.transferFrom(address(this), msg.sender, amount);

1 Answer 1


You should be able to transfer tokens via the transfer() function:

 function transfer(address recipient, uint amount) external returns (bool);

Transfer does not require approval.

  • Thank you. I changed to transfer and it worked.
    – Poutine
    May 11, 2022 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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