0

What I basically have is my own ERC20 smart contract.

I want the following functionality in my smart contract:

A user transfers X amount of an ERC20 token (I can choose/change this token at any time). I process the payment. Based on the amount of the tokens sent to my contract, I send the user Y amount of my own ERC20 token.

Can I code the above functionality as a function in Solidity?

  • Yes, it could be done, start by accepting ERC20 as payments: https://ethereum.stackexchange.com/questions/23567/accepting-an-erc20-token-as-payment. – Ismael Feb 21 '22 at 21:48

1 Answers1

0

So to accept other token is actually pretty simple i will write a sample here so you can look into and do it your self .

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./Token1.sol"; ///TestC token contract

contract FFA {

TestC _token = TestC(0x93e8C4b313966461239605A771bc10cfb79748F3);   // Create pointer to your smart contract



function transfer(address _to,uint256 _amount)public {  // create function that you want to use to fund your contract or transfer that token
    require(_token.transferFrom(msg.sender,_to,_amount)); // call function of your token contract to do the transfer
}

}

so your contract can accept any token this way

yahoo5000
  • 129
  • 7