0

Taking help of openzepplin, in making ERC20 token , I now have to use this token in multiple contracts for various use.

So, how do I code my ERC20 token into other contracts, so that at time of amount transfer, metamask will send tokens ( not eth).

Any query, please do let me know & I'll share immediately.

  • Please share the relevant code. – goodvibration Sep 24 at 12:40
1

You can import IERC20 interface from OpenZepplin to use with your token address:

import {IERC20} from "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";

contract Test {

    function foo() public {
        // Reference to deployed token
        IERC20 token = IERC20(0x0000000000000000000000000000000000000023);

        // Obtain sender balance
        uint256 funds = token.balanceOf(msg.sender);

        // Transfer from sender
        token.transferFrom(msg.sender, address(this), funds);
    }
}

Note: You should be aware that Test contract is making the call, so inside the token msg.sender is Test contract.

| improve this answer | |

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