diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2018-04-15 06:50:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-15 06:50:13 +0800 |
commit | 73ca3e8a1eaf929dac60ce0a154975fa46b2040e (patch) | |
tree | d38235eaaf27c1593bea216a4363c3c6c3f30da0 /docs | |
parent | 95c49b367eaaec313b335d0953b5871dd445052c (diff) | |
parent | 559fa58ddf3d6b32242286e392b2695d56594423 (diff) | |
download | dexon-solidity-73ca3e8a1eaf929dac60ce0a154975fa46b2040e.tar.gz dexon-solidity-73ca3e8a1eaf929dac60ce0a154975fa46b2040e.tar.zst dexon-solidity-73ca3e8a1eaf929dac60ce0a154975fa46b2040e.zip |
Merge pull request #3882 from ethereum/abi_doc
Document ABI encoding functions.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/miscellaneous.rst | 5 | ||||
-rw-r--r-- | docs/units-and-global-variables.rst | 25 |
2 files changed, 28 insertions, 2 deletions
diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 8270727f..c7c32528 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -317,6 +317,11 @@ The following is the order of precedence for operators, listed in order of evalu Global Variables ================ +- ``abi.encode(...) returns (bytes)``: :ref:`ABI <ABI>`-encodes the given arguments +- ``abi.encodePacked(...) returns (bytes)``: Performes :ref:`packed encoding <abi_packed_mode>` of the given arguments +- ``abi.encodeWithSelector(bytes4 selector, ...) returns (bytes)``: :ref:`ABI <ABI>`-encodes the given arguments + starting from the second and prepends the given four-byte selector +- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(signature), ...)``` - ``block.blockhash(uint blockNumber) returns (bytes32)``: hash of the given block - only works for 256 most recent, excluding current, blocks - deprecated in version 0.4.22 and replaced by ``blockhash(uint blockNumber)``. - ``block.coinbase`` (``address``): current block miner's address - ``block.difficulty`` (``uint``): current block difficulty diff --git a/docs/units-and-global-variables.rst b/docs/units-and-global-variables.rst index 9d5821d5..51f7b9f3 100644 --- a/docs/units-and-global-variables.rst +++ b/docs/units-and-global-variables.rst @@ -44,9 +44,10 @@ Special Variables and Functions =============================== There are special variables and functions which always exist in the global -namespace and are mainly used to provide information about the blockchain. +namespace and are mainly used to provide information about the blockchain +or are general-use utility functions. -.. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin +.. index:: abi, block, coinbase, difficulty, encode, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin Block and Transaction Properties @@ -90,6 +91,26 @@ Block and Transaction Properties You can only access the hashes of the most recent 256 blocks, all other values will be zero. +.. index:: abi, encoding, packed + +ABI Encoding Functions +---------------------- + +- ``abi.encode(...) returns (bytes)``: ABI-encodes the given arguments +- ``abi.encodePacked(...) returns (bytes)``: Performes packed encoding of the given arguments +- ``abi.encodeWithSelector(bytes4 selector, ...) returns (bytes)``: ABI-encodes the given arguments + starting from the second and prepends the given four-byte selector +- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(signature), ...)``` + +.. note:: + These encoding functions can be used to craft data for function calls without actually + calling a function. Furthermore, ``keccak256(abi.encodePacked(a, b))`` is a more + explicit way to compute ``keccak256(a, b)``, which will be deprecated in future + versions. + +See the documentation about the :ref:`ABI <ABI>` and the +:ref:`tightly packed encoding <abi_packed_mode>` for details about the encoding. + .. index:: assert, revert, require Error Handling |