0

Is BranchBridgeAgentFactory the parent contract?

Will there be two different address? Or just one?

pragma solidity ^0.8.0;
contract TestBranchBridgeAgentFactory is BranchBridgeAgentFactory {
    /*///////////////////////////////////////////////////////////////
                             CONSTRUCTOR
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Constructor for Bridge Agent Factory Contract.
     *  @param _rootChainId Root Chain Layer Zero Id.
     *  @param _rootBridgeAgentFactoryAddress Root Bridge Agent Factory Address.
     *  @param _localCoreBranchRouterAddress Local Core Branch Router Address.
     *  @param _localPortAddress Local Branch Port Address.
     *  @param _owner Owner of the contract.
     */
    constructor(
        uint16 _rootChainId,
        address _rootBridgeAgentFactoryAddress,
        address _localCoreBranchRouterAddress,
        address _localPortAddress,
        address _owner
    )
        BranchBridgeAgentFactory(
            _rootChainId,
            _rootChainId,
            _rootBridgeAgentFactoryAddress,
            address(0),
            _localCoreBranchRouterAddress,
            _localPortAddress,
            _owner
        )
    {}
1
  • What two different addresses? Explain your question please. Sep 23, 2023 at 15:33

2 Answers 2

0

It's hard to answer your question, since you're not providing enough information on the issue, but I'll give it a try.

I believe you're confusing inheritance of contracts with the deployment of different contracts. In the contract you've supplied, there'll only be one address for the contract. Inheritance of other contracts works in a way, where you inherit functions and so on from those contracts (in this case the TestBranchBridgeAgentFactory contract inherits from the BranchBridgeAgentFactory), but it'll all end up with the same address when compiled and deployed. You're not deploying different contracts, but only inheriting from the contract, that the contract in question inherits from.

So, there are no so-called parent or child contracts, as when you deploy a child contract from a parent contract. Instead there are base and derived contracts, where the contract in question is the derived contract and the contract it inherits from is the base contract.

At least, that's how I understand it. I hope this will clarify some stuff for you! :)

1
  • I was researching and noticed that, Hmm somehow you are able to call the instance of the parent/derived contract. So BranchBridgeAgentFactory branchbridgeagentfactory with the address of TestBranchBridgeAgentFactory. It's weird that you can do that. Any reason would anyone do it? Dec 9, 2023 at 8:44
0

Inheritance is a way to, well, inherit functionality from another contract, during the development phase. Once a contract is deployed to a blockchain, it can't be inherited from directly anymore.

If contract A inherits contract B, and you want to deploy contract A, the compiler flattens the files. This means the compiler just copies all of the code from contract B into contract A - the result is therefore just one contract. Typically, you then compile and deploy this contract A, so there will be only one address.

In theory, you could also deploy contract B (unless it's an abstract contract) - then it wouldn't have any of the functionality from contract A. Usually this is not desired.

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.