Search code examples
blockchainsoliditynft

Does Solidity language has namespace?


In Solidity langugae, I define ContractA and ContractB.

Inside ContractA declare structure A and I want to access A inside ContractB.

contract ContractA {
  struct A {
  uint age;
  string name;
  }

  // Some other methods and data structure
}

contract ContractB {
  // how to access structure A.
}

I don't want to use Inheritance or library syntax.


Solution

  • There's nothing like namespace of C# in Solidity.

    If you would like to share the struct between contract, then declare a library.

    library Structs {
        struct AnyName {
            uint256 id;
        }
    }
    
    contract ContractA {
        Structs.AnyName go;
    }