Reputation: 485
I'm new to solidity and I wanted to develop a subscription contract where a user can subscribe to a merchants plan and pay. But I'm unable to subscribe function and transfer the token to merchant.
I'm using open zeppelin ERC20 standard token to transfer.
IERC20 token = IERC20(plans[planId].token);
token.transferFrom(
payable(msg.sender),
payable(plan.merchant),
plan.amount
);
I don't know why but this keeps giving me allowance error even though I have increased the allowance of the user.
Upvotes: 0
Views: 483
Reputation: 43481
Since you're invoking the token.transferFrom()
from the subscription contract, the token owner needs to increaseAllowance()
for the subscription contract to manipulate their tokens.
Example:
0x123
.0x456
, and it has 18
decimals.increaseAllowance(0x123, 500 * 1e18)
on the token contract in order to increase the allowance by 500 tokens.
500000000000000000000
because it includes the decimals as units as well).Upvotes: 1