0

I have the following code in AuthorTokens.sol:

    Files files;

    // ...

    function mintAuthor(address _owner) external {
        require(msg.sender == files, "System function");
        uint256 _id = _sellerToToken(_owner);
        balances[_id][_owner] = 10**digitsConstant;
        TransferSingle(msg.sender, 0, _owner, _id, 10**digitsConstant);
    }

This function should be called by the contract Files.sol, when a new "author" is added.

So, I have a mutual dependency of two contracts: Files and AuthorTokens. How to deal with this? Should I set both contracts to point to addresses of each other?

I could combine the two contracts into one but Files is ERC-20 and AuthorTokens is ERC-1155.

So, what to do?

2
  • 1
    It is clear the dependency of AuthorTokens on Files, but the other way around is not obvious. What is the dependency of Files on AuthorTokens. In the first case it should be possible to deploy Files contract, then call deploy AuthorTokens with Files' address as parameter. – Ismael Sep 2 '20 at 4:29
  • 1
    The "other way" is that Files needs to call mintAuthor. – porton Sep 2 '20 at 10:00
1

One solution is to move the contract initialization in a separate function

contract Files {
    ERC20 authorToken;
    function init(ERC20 token) public {
        require(address(authorToken) == address(0x0));
        authorToken = token;
    }
}


contract AuthorToken {
    Files files;
    function init(Files f) public {
        require(address(files) == address(0x0));
        files = f;
    }
}

The deployment will be slightly more complex because you have to make the calls to the init functions.

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.