I want to airdrop ERC20 tokens through Merkle tree airdrop and I created the root hash and got the Merkleproof for one of the addresses. Still, while claiming manually from remix it's showing ""message": "execution reverted: ERC20: insufficient allowance" allowance error."
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/MerkleProof.sol";
contract MerkleDistributor{
address public immutable token;
bytes32 public immutable merkleRoot;
uint256 public dropAmount;
address public owner;
// This is a packed array of booleans.
mapping(address => bool) public whitelistClaimed;
constructor(address token_, bytes32 merkleRoot_,uint256 dropAmount_) {
token = token_;
merkleRoot = merkleRoot_;
dropAmount = dropAmount_;
owner = msg.sender;
}
function claim( bytes32[] calldata merkleProof) external {
//Basic data validation to ensure that wallet hasn't Claimed
require(!whitelistClaimed[msg.sender] , 'MerkleDistributor: Drop already claimed.');
// Verify the merkle proof.
bytes32 leaf = keccak256(abi.encodePacked(msg.sender));
require(MerkleProof.verify(merkleProof, merkleRoot, leaf), 'MerkleDistributor: Invalid proof.');
// Mark it claimed and send the token.
whitelistClaimed[msg.sender] = true;
require(IERC20(token).transferFrom(owner , msg.sender, dropAmount), 'MerkleDistributor: Transfer failed.');
}
}
this was the airdrop code,
pragma solidity ^0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract CryptoNix is ERC20 {
address public owner;
constructor()ERC20 ("CryptoNix" , "CNX"){
owner = msg.sender;
_mint(msg.sender , 10000000000000000000000);
}
}
This was the token code,
I gave the approval also still showed an allowance error.
Please help with how can users can claim airdrop tokens from the remix.