0

I'm developing a function that accepts any kind of ERC20 token, and transfer it to the provided address. The idea is to execute the function connecting Metamask address, and transferring the desired kind of ERC20 tokens to the desired Ethereum address.

It is not exactly a payable function, since it is not only receiving ETHer. In the examples I have seen, they specify the address contract of the desired ERC20 token, but in this case it could be any ERC20 token.

How could I get the selected token from Metamask, to specify the ERC20 contract address to my Smart Contract?

UPDATE: I think Uniswap do something like I want to achieve in this contract.

They import IERC20 standard Smart Contract, and use it to initialize any pair of tokens.

// called once by the factory at time of deployment
function initialize(address _token0, address _token1) external {
    require(msg.sender == factory, 'UniswapV2: FORBIDDEN'); // sufficient check
    token0 = _token0;
    token1 = _token1;
}

Thanks

5
  • What is "ETH tokens"? Commented Dec 23, 2020 at 13:22
  • ETH native tokens I mean (accepted ones with payable functions) Commented Dec 23, 2020 at 13:31
  • That's ether, not tokens. Commented Dec 23, 2020 at 13:39
  • You are rightm ether. Any idea? Commented Dec 23, 2020 at 13:42
  • To my understanding, you are asking for a 3rd party support here, and not for help in a technical coding problem. If I'm wrong, then please explain the exact technical coding problem that you are dealing with. Commented Dec 23, 2020 at 13:51

1 Answer 1

1

For this use-case, Metamask is only used as a wallet to hold ERC20 tokens and sign transactions to transfer them, but you don't need to select any token (but just have them already).

On the other hand, every ERC20 token has its own contract address, so you need to manage it through your smart contract or your frontend/backend via web3.js or ethers.js. If you want to handle any ERC20 token, then you need to define all their contract addresses (and... there are a few).

As for the smart contract function, here you have an example that either receives ETH or ERC20 tokens:

Receive ETH/ERC20

1
  • Ok thanks, so definitively there is not any way to accept any ERC20 token in a Smart Contract. I thought that maybe being all ERC20, I could use transfer functions with them. I was thinking in something like Uniswap UniswapV2Pair Commented Dec 24, 2020 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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