mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Remove initialisation of contract with wei FAQ item
This commit is contained in:
parent
d6b8521ed5
commit
e2642c4d9d
@ -2,37 +2,5 @@
|
||||
Frequently Asked Questions
|
||||
###########################
|
||||
|
||||
This list was originally compiled by `fivedogit <mailto:fivedogit@gmail.com>`_.
|
||||
|
||||
******************
|
||||
Advanced Questions
|
||||
******************
|
||||
|
||||
How do I initialize a contract with only a specific amount of wei?
|
||||
==================================================================
|
||||
|
||||
Currently the approach is a little ugly, but there is little that can be done to improve it.
|
||||
In the case of a ``contract A`` calling a new instance of ``contract B``, parentheses have to be used around
|
||||
``new B`` because ``B.value`` would refer to a member of ``B`` called ``value``.
|
||||
You will need to make sure that you have both contracts aware of each other's presence and that ``contract B`` has a ``payable`` constructor.
|
||||
In this example::
|
||||
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
contract B {
|
||||
constructor() public payable {}
|
||||
}
|
||||
|
||||
contract A {
|
||||
B child;
|
||||
|
||||
function test() public {
|
||||
child = (new B).value(10)(); //construct a new B with 10 wei
|
||||
}
|
||||
}
|
||||
|
||||
More Questions?
|
||||
===============
|
||||
|
||||
If you have more questions or your question is not answered here, please talk to us on
|
||||
If your question is not answered here, please talk to us on
|
||||
`gitter <https://gitter.im/ethereum/solidity>`_ or file an `issue <https://github.com/ethereum/solidity/issues>`_.
|
||||
|
Loading…
Reference in New Issue
Block a user