I have a token contract(ERC20) A, then another contract B inherited from A (B is A). A contract C imported B.

questions are:

  1. if I deployed B alone, is the address of this contract B represent the token A address?
  2. if I deploy A first, then deploy B, are the tokens minted from A and the token minted from B the same?
  3. if I deployed C alone, what's the address of Token A?
  4. if I want to mint A token in C, what is the best way to do it?

Please please please help me. im so confused.

1 Answer 1

  1. Since B inherits from A the deployed contract contains the methods from both A and B, so the same address can be used as both A and B

  2. When contracts A and B are deployed separately you have two addresses that are unrelated. For example you can deploy the same contract twice and obtain two completely independent addresses.

  3. If contract C imports B but it doesn't inherit from B then when C is deployed there's no A.

    If contract C inherits from B then 1. applies C address = B address = A address

  4. Import A from contract C and pass A address as parameter in C constructor where you store a reference to A.

import "A.sol";

contract C {
    A token;

    constructor(A _token) public {
        token = _token;

    function deposit(uint amount) public {
        token.transferFrom(msg.sender, address(this), amount);

  • Thank you! much appreciate!
    – Ye Wang
    Sep 28, 2020 at 11:35
  • but _mint is a private function, how can i call mint in C without ineriting A?
    – Ye Wang
    Sep 28, 2020 at 11:42
  • @YeWang I can think two options: 1/ add a public method mint in A, and allow only C to call it, 2/ mint by owner and transfer to C so it doesn't have to mint, but I'm pretty sure there are many other ways to achieve something similar.
    – Ismael
    Sep 28, 2020 at 16:54

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.