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?

1

1 Answer 1

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

7
  • This function is accepting ETH as payment to transfer their own ERC20 token. What I'd like to do is accept another ERC20 token. When transferred to my contract, I'd like to transfer them my own ERC20 token
    – duskdusk13
    Feb 20, 2022 at 16:59
  • i assume you would just use token contract address instead of eth address
    – yahoo5000
    Feb 20, 2022 at 17:02
  • But how would I check if the user transferred me that certain token within my smart contract?
    – duskdusk13
    Feb 20, 2022 at 17:04
  • you can use uniswap or something and create liquidity pool in your smart contract and exchange them this way
    – yahoo5000
    Feb 20, 2022 at 17:10
  • would you possibly have a tutorial on how to do that?
    – duskdusk13
    Feb 20, 2022 at 17:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.