As per the Solidity 0.4.16 documentation, contracts are similar to the concept of a Class of an object oriented language. That being said, can we create a Contract within a contract.

IF yes, then please explain with a working sample or atleast provide a classification on various kinds of nested contracts that we can create.

IF no, what is stopping us from doing i.e. practical challenges while taking this decision of not having nested contracts in solidity.

Issue raised in similar lines but NOT directly addressing this question: testrpc, contract creating contract not mined?


Solidity allows for a contract to inherit from other contracts.

Solidity also allows for custom data structs within a contract. These struct types could take the place of a "private class" (Java) contract-within-a-contract for most uses.

And Solidity contracts can create new contracts ("factory" pattern), though the new contracts don't need to have any link back to the "parent". Contracts can call methods on all other contracts, so one contract can treat another one as a "child" or a "library" just in how it uses that contract, but there's no formal relationship between them.

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.