0

I would like to ask a question about token distribution with overriding ERC20 transferFrom function.


IERC20 Token;
  function buy(uint256 id)
        external
        onlyCardPayable(id, PaymentTypes.Buy)
    {
        uint256 amount;
        if (winners[id][msg.sender].amount == 0) {
            amount = collection[id].amount;
        }
        amount = winners[id][msg.sender].amount;

        distributeTokens(msg.sender, address(this), token, amount);
        transferFrom(address(this), msg.sender, id, 1, "");
        sold += 1;

        emit CardBought(msg.sender, id, PaymentTypes.Buy, amount);
    }
 function distributeTokens(
        address from,
        address to,
        IERC20 token,
        uint256 amount
    ) internal {
        uint256 totalShare =
                shares[_charityOne] +
                shares[_charityTwo] +
                shares[_toAddress];
        // Check if transfer reverts due to 2300 gas limit.
        // We should change to call than.
        token.transferFrom(from, to, amount);
        payable(_charityOne).transfer(amount * (shares[_charityOne] / 100));
        payable(_charityTwo).transfer(amount * (shares[_charityTwo] / 100));
        payable(_toAddress).transfer(amount * (shares[_toAddress] / 100));
    }

Question is this -> Is this possible? Getting token to contract and in next line distribute it.

2
  • What's the question ? – clement Mar 31 at 20:08
  • I updated sorry for inconvenience – Mert Anıl Gören Mar 31 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.