diff options
author | chriseth <chris@ethereum.org> | 2016-08-16 22:13:56 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-16 22:13:56 +0800 |
commit | 480cf384bbe923bdb3c5e1a16fb4670a2db6c03c (patch) | |
tree | 314a8489030bdd9c2c8f0f6496a259eaaa6259e2 /docs | |
parent | 70994f49960dd7066ad5de6fe835ccb1201269a6 (diff) | |
parent | 2a560b798b5f5ece6dfb500a8e03409c62332e41 (diff) | |
download | dexon-solidity-480cf384bbe923bdb3c5e1a16fb4670a2db6c03c.tar dexon-solidity-480cf384bbe923bdb3c5e1a16fb4670a2db6c03c.tar.gz dexon-solidity-480cf384bbe923bdb3c5e1a16fb4670a2db6c03c.tar.bz2 dexon-solidity-480cf384bbe923bdb3c5e1a16fb4670a2db6c03c.tar.lz dexon-solidity-480cf384bbe923bdb3c5e1a16fb4670a2db6c03c.tar.xz dexon-solidity-480cf384bbe923bdb3c5e1a16fb4670a2db6c03c.tar.zst dexon-solidity-480cf384bbe923bdb3c5e1a16fb4670a2db6c03c.zip |
Merge pull request #710 from chriseth/throwFailedCreate
BREAKING: Throw if contract creation fails.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/control-structures.rst | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/docs/control-structures.rst b/docs/control-structures.rst index eb337928..ac24a5a9 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -106,6 +106,43 @@ of unused parameters (especially return parameters) can be omitted. } } +.. index:: ! new, contracts;creating + +.. _creating-contracts: + +Creating Contracts via new +========================== + +A contract can create a new contract using the ``new`` keyword. The full +code of the contract to be created has to be known and thus recursive +creation-dependencies are now possible. + +:: + + contract D { + uint x; + function D(uint a) { + x = a; + } + } + contract C { + D d = new D(4); // will be executed as part of C's constructor + + function createD(uint arg) { + D newD = new D(arg); + } + + function createAndEndowD(uint arg, uint amount) { + // Send ether along with the creation + D newD = (new D).value(amount)(arg); + } + } + +As seen in the example, it is possible to forward Ether to the creation, +but it is not possible to limit the amount of gas. If the creation fails +(due to out-of-stack, not enough balance or other problems), an exception +is thrown. + Order of Evaluation of Expressions ================================== |