mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #1787 from ethereum/docs-gasvalue
Document the .value() and .gas() modifiers
This commit is contained in:
commit
58334cf4ac
@ -113,8 +113,8 @@ actual contract has not been created yet.
|
|||||||
Functions of other contracts have to be called externally. For an external call,
|
Functions of other contracts have to be called externally. For an external call,
|
||||||
all function arguments have to be copied to memory.
|
all function arguments have to be copied to memory.
|
||||||
|
|
||||||
When calling functions
|
When calling functions of other contracts, the amount of Wei sent with the call and
|
||||||
of other contracts, the amount of Wei sent with the call and the gas can be specified::
|
the gas can be specified with special options ``.value()`` and ``.gas()``, respectively::
|
||||||
|
|
||||||
contract InfoFeed {
|
contract InfoFeed {
|
||||||
function info() payable returns (uint ret) { return 42; }
|
function info() payable returns (uint ret) { return 42; }
|
||||||
@ -127,8 +127,8 @@ of other contracts, the amount of Wei sent with the call and the gas can be spec
|
|||||||
function callFeed() { feed.info.value(10).gas(800)(); }
|
function callFeed() { feed.info.value(10).gas(800)(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
The modifier ``payable`` has to be used for ``info``, because otherwise,
|
The modifier ``payable`` has to be used for ``info``, because otherwise, the `.value()`
|
||||||
we would not be able to send Ether to it in the call ``feed.info.value(10).gas(800)()``.
|
option would not be available.
|
||||||
|
|
||||||
Note that the expression ``InfoFeed(addr)`` performs an explicit type conversion stating
|
Note that the expression ``InfoFeed(addr)`` performs an explicit type conversion stating
|
||||||
that "we know that the type of the contract at the given address is ``InfoFeed``" and
|
that "we know that the type of the contract at the given address is ``InfoFeed``" and
|
||||||
@ -235,7 +235,7 @@ creation-dependencies are not possible.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
As seen in the example, it is possible to forward Ether to the creation,
|
As seen in the example, it is possible to forward Ether to the creation using the ``.value()`` option,
|
||||||
but it is not possible to limit the amount of gas. If the creation fails
|
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
|
(due to out-of-stack, not enough balance or other problems), an exception
|
||||||
is thrown.
|
is thrown.
|
||||||
|
@ -123,6 +123,8 @@ In a similar way, the function ``delegatecall`` can be used: The difference is t
|
|||||||
|
|
||||||
All three functions ``call``, ``delegatecall`` and ``callcode`` are very low-level functions and should only be used as a *last resort* as they break the type-safety of Solidity.
|
All three functions ``call``, ``delegatecall`` and ``callcode`` are very low-level functions and should only be used as a *last resort* as they break the type-safety of Solidity.
|
||||||
|
|
||||||
|
The ``.gas()`` option is available on all three methods, while the ``.value()`` option is not supported for ``delegatecall``.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
All contracts inherit the members of address, so it is possible to query the balance of the
|
All contracts inherit the members of address, so it is possible to query the balance of the
|
||||||
current contract using ``this.balance``.
|
current contract using ``this.balance``.
|
||||||
|
Loading…
Reference in New Issue
Block a user