-1

I would like to send some IERC20 tokens from metamask to a contract controlled by my webpage

I link an HTML button action to the following javascript function. This works well when ether is sent directly from metamask after accepting confirming/linking account from metamask with webpage

  const placeFunds = async (side, e) => {
    e.preventDefault();
    await contract.getFunds(
      side, 
      {value: e.target.elements[0].value}
    );

Now for the IERC20 token, I would like to figure out the IERC20 token address before passing to the contract function. Where is the token address stored in javascript/how do I get that info, as I want the contract to accept only specific ERC20 tokens?

  const placeFunds = async (side, e) => {
    e.preventDefault();
    await contract.getFunds(
      side, TOKENADDRESS, 
      {value: e.target.elements[0].value}
    );
adam
  • 655
  • 1
  • 10
  • 31

1 Answers1

0

The tokens are not stored in javascript. Whenever you want a new token to be added in metamask, you might have to add it yourself because metamask also doesn't know about it. If you don't know the token you are going to transfer, you can use some tool like Moralis to get all erc20 tokens of the user with Moralis.Web3.getAllERC20

sorold
  • 475
  • 7
  • 17
  • I already have the USDC in metamask. Now I connect my metamask account the website and try to transfer some tokens using submit button. Submit button calls placeFunds javascript function, the e.target.elements[0].value takes the entry in a box and from there I am calling solidity function getFunds. This function needs TOKENADDRESS for USDC, but for ether I don't need it as I use payable and directly transfer ether to contract. Does that clarify what I am trying to do – adam Jun 30 '22 at 20:26
  • Just go in you metamask, click on the USDC, click on the three dots and then see it in the explorer. That should show up the address you need, then – sorold Jun 30 '22 at 20:30