0

I am trying to make a smart contract where calling a function named transferERC20, you can deposit your erc20 tokens into the smart contract.

Here is the code at the moment:

pragma solidity ^0.5.0;

import "./ERC20.sol";

contract GameTokenERC20 is ERC20{

  function transferERC20(uint _value) public{
    approve(address(this), _value);
   // transfer(address(this), _value);
   emit Approval(msg.sender, address(this), _value);
   transferFrom(msg.sender,address(this), _value);
  }


}

Basically calling the function you should be able to deposit any erc20 token to my contract address.

I have tried to deploy it in remix but metamask doesn't let me set the token that I want to send, it just creates the transaction.

My questions are :

1) If it doesn't work in the remix IDE, should I try it from web3 ? 2) How does the user say which token he wants to send ? I'll have to put a contract address for each token ?

I think I am missing something as the user will just have to deposit the erc20 token inside the contract.

Thanks to all

1

Since you're transferring from within the token contract itself, you can just do this:

  function transferERC20(uint _value) public {
    transfer(address(this), _value);
  }

msg.sender will be preserved for transfer since this is an internal call.

Your Answer

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

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