Skip to content

Commit

Permalink
doc: document method_id kwarg to abi_encode (#2437)
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper authored Aug 27, 2021
1 parent be9d307 commit 16e4834
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions docs/built-in-functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -631,19 +631,24 @@ Utilities

* ``*args``: Arbitrary arguments
* ``ensure_tuple``: If set to True, ensures that even a single argument is encoded as a tuple. In other words, ``bytes`` gets encoded as ``(bytes,)``. This is the calling convention for Vyper and Solidity functions. Except for very specific use cases, this should be set to True. Must be a literal.
* ``method_id``: A literal hex or Bytes[4] value to append to the beginning of the abi-encoded bytestring.

Returns a bytestring whose max length is determined by the arguments. For example, encoding a ``Bytes[32]`` results in a ``Bytes[64]`` (first word is the length of the bytestring variable).

.. code-block:: python
@external
@view
def foo() -> Bytes[128]:
def foo() -> Bytes[132]:
x: uint256 = 1
y: Bytes[32] = "234"
return _abi_encode(x, y)
return _abi_encode(x, y, method_id=method_id("foo()"))
.. code-block:: python
>>> ExampleContract.foo().hex()
"0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000033233340000000000000000000000000000000000000000000000000000000000"
"c2985578"
"0000000000000000000000000000000000000000000000000000000000000001"
"0000000000000000000000000000000000000000000000000000000000000040"
"0000000000000000000000000000000000000000000000000000000000000003"
"3233340000000000000000000000000000000000000000000000000000000000"

0 comments on commit 16e4834

Please sign in to comment.