I’m getting 0 allowances even after approving admin to spend, although msg.sender has a balance of 100. I tried to sleep for 10 seconds too before executing transferFrom() it fails and even after that allowance is 0. But it didn’t work.
function applyForVerification(uint _amount) public {
require(msg.sender != admin, "admin can't apply verification");
console.log(IERC20(token).balanceOf(msg.sender));
bool _success = IERC20(token).approve(address(this), _amount);
if (_success) {
console.log(IERC20(token).allowance(msg.sender, address(this)));
account[msg.sender].status = Status.Requested;
emit PendingVerifications(msg.sender, account[msg.sender].status);
} else {
revert("failed to approve");
}
}
remix logs
console.log:
100
10
The applyForVerification() in which the approval was supposed to work is the second one in the screenshot and even after 5 to 6 tests I checked allowances it's still 0. In between those tests, I also halted execution for 10 seconds.
verifyArtist()
function verifyArtist(address _address, uint _amount) public onlyAdmin {
require(account[_address].status == Status.Pending, "invalid status for verification");
address clone = Clones.clone(implementation);
Implementation(clone).initialize(_address, tiers.tier1, tiers.tier2 , admin, token, _amount);
implementationAddress[_address] = address(clone);
account[_address].status = Status.Verified;
console.log("Contract Address", address(clone));
emit PendingVerifications(_address, account[_address].status);
emit Verified(_address, address(clone));
}
Implementation Contract Initialization
function initialize(address _address, uint _tier1, uint _tier2, address _admin, address _token, uint _amount) public initializer payable {
address = _address;
admin = _admin;
token = _token;
tiers = Tiers(_tier1, _tier2);
console.log("Allowance", IERC20(token).allowance(_address, msg.sender));
IERC20(token).transferFrom(_address, address(this), _amount);
}
remix logs:
console.log:
Allowance 10
transact to Factory.verifyArtist errored: VM error: revert.
revert
The transaction has been reverted to the initial state.
Reason provided by the contract: "ERC20: transfer amount exceeds allowance".
Updates
My bad I was wrong at spender, when the clone has created the msg.sender for transferFrom() in initialize() in implementation contract will be the factory contract so I have made necessary changes to the spender. In the remix, I’m getting the allowance value(10) but still, transferFrom() reverts with exceeded allowance reason. And in hardhat, the allowance is still 0.