1

Im currently creating a DEX where users swap tokens. However I have to use IERC20 transferfrom( address sender, address recipient, uint256 amount). But for this to happen the 3rd party(1inch) will need permission to approve and withdraw.

Questions/Problems:

  1. What address should be sender/from? -(mine or 1inch?)
  2. what address should be the recipient/to?- (mine or 1inch?)
  3. _tokenAddress is token that the user wants. Is this correct?
**My Current Code:**

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

import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol";

contract testTransfer{ using SafeMath for uint256; mapping(address => uint) balances;

address private Commowner = payable (0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2) ;// account that take commission uint256 public commission = 1; // we want 1%

function transferFrom(address from, address to, uint amount, address _tokenAddress ) public payable {

uint fee = amount * commission / 10000; // we want 1%

// 0x11 is 1inch (sender/from), msg.sender/account (to) the address trying to recieve tokens, 1 is the amount, //_tokenAddress the erc20 token that we want. IERC20(_tokenAddress).transferFrom(from, to, amount);

balances[from] = balances[from].sub(fee); balances[Commowner] = balances[Commowner].add(fee); // we get the commission. // emit transfer(from,to,value);

}}

Thanks for your help Dee

DeeGold
  • 11
  • 2
  • Read the transferFrom behavior https://ethereum.stackexchange.com/questions/46457/send-tokens-using-approve-and-transferfrom-vs-only-transfer. In some cases you need to use transfer and in other cases transferFrom. – Ismael Aug 14 '22 at 15:44
  • Thanks Ismael for responding , I've read the the info in the link you posted. However my main question is just using the transferFrom it will allow a 3rd party to withdraw but what if a user/customer want to swap an erc20 token for another erc20 token I wouldn't just use transferFrom by itself. or can it? @Ismael – DeeGold Aug 17 '22 at 00:08

0 Answers0