I'm reading this post of this page "Solidity, create contract from contract".

And i have a question about this post, How i can define the estructure of the contract " address newContract = new Contract(name);" ?

For structure i mean the functions inside the created contract. I don't know if it is possible or not, but i'm looking for a answer about this question and i don't found nothing.

1 Answer 1


In the linked example, the structure of the contract that is created by the factory contract is specified in the same source code file as the factory contract that creates it. The compiler (solc) will compile the source code of the created contract, and then compile the factory contract so that it knows how to create a contract with that compiled code.

A contract can create a contract with arbitrary data (which becomes the child contract's code) so in theory it should be possible to build code dynamically inside the factory contract then instantiate a contract using that code. But it is probably not practical to actually compile code inside a contract, which would require a Solidity compiler written in Solidity.

There may be some weird situations where you want to build compiled code with some initial variables set dynamically in your contract, then use that data to instantiate a contract, but it would be an unusual thing to do. Usually you want to define the structure of the contract in advance (or several different contracts, if you have several different patterns) in normal source code and instantiate an instance of the predefined contract, then call the newly-created contract to set your initial variables that will affect its behaviour.

  • Nice, really good explanation. You know if exist some "desing patterns" or somethink like this for solidity ?
    – Gawey
    May 23, 2017 at 8:42

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.