Ethereum ABI Utils
Project description
Ethereum Contract
=================
|Build Status| |Documentation Status| |PyPi version| |PyPi downloads|
Python utilities for working with the Ethereum ABI
Installation
------------
.. code:: sh
pip install eth-abi
Documentation
-------------
Decoding
~~~~~~~~
These functions are intended for decoding return values from the EVM.
- ``eth_abi.decode_single(type, data)``
This function tries to decode ``data`` into the python type that
corresponds to the provided ``type``. This function accepts data of type
bytes.
.. code-block:: python
::
>>> decode_single('uint256', b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0009')
12345
The **value** parameter is expected to be one of the recognized EVM
types.
.. note:: This function cannot be used to decode dynamic or array types
such as ``bytes32[]``.
- ``eth_abi.decode_abi(types, data)``
This function decodes ``data`` into the python type corresponding to the
provided ``types``. This function accepts arrays of type byte.
.. code-block:: python
::
>>> decode_abi(['uint256'], b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0009')
[12345]
>>> decode_abi(['bytes32', 'bytes32'], b'a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
['a', 'b']
The **values** parameter is expected to be an iterable whose values are
all one of the recognized EVM types.
Encoding
~~~~~~~~
These functions are intended for encoding python values into
representations that are suitable for interacting with the EVM.
- ``eth_abi.encode_single(type, value)``
This function encodes ``value`` in the ABI encoding for the provided
``type``.
.. code-block:: python
::
>>> encode_single('uint256', 12345)
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0009'
The **value** parameter is expected to be one of the recognized EVM
types.
.. note:: This function cannot be used to encode array types such as
``bytes32[]``.
- ``eth_abi.encode_abi(types, values)``
This function encodes ``values`` in the ABI encoding for the
corresponding type provided by the ``types`` argument.
.. code-block:: python
::
>>> encode_abi(['uint256'], [12345])
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0009'
>>> encode_abi(['bytes32', 'bytes32'], ['a', 'b'])
b'a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
The **values** parameter is expected to be an iterable whose values are
all one of the recognized EVM types.
Development
-----------
Clone the repository and then run:
.. code:: sh
pip install -e . -r requirements-dev.txt
Running the tests
~~~~~~~~~~~~~~~~~
You can run the tests with:
.. code:: sh
py.test tests
Or you can install ``tox`` to run the full test suite.
Releasing
~~~~~~~~~
Pandoc is required for transforming the markdown README to the proper
format to render correctly on pypi.
For Debian-like systems:
::
apt install pandoc
Or on OSX:
.. code:: sh
brew install pandoc
To release a new version:
.. code:: sh
make release bump=$$VERSION_PART_TO_BUMP$$
How to bumpversion
^^^^^^^^^^^^^^^^^^
The version format for this repo is ``{major}.{minor}.{patch}`` for
stable, and ``{major}.{minor}.{patch}-{stage}.{devnum}`` for unstable
(``stage`` can be alpha or beta).
To issue the next version in line, specify which part to bump, like
``make release bump=minor`` or ``make release bump=devnum``.
If you are in a beta version, ``make release bump=stage`` will switch to
a stable.
To issue an unstable version when the current version is stable, specify
the new version explicitly, like
``make release bump="--new-version 4.0.0-alpha.1 devnum"``
.. |Build Status| image:: https://travis-ci.org/ethereum/eth-abi.png
:target: https://travis-ci.org/ethereum/eth-abi
.. |Documentation Status| image:: https://readthedocs.org/projects/eth-abi/badge/?version=latest
:target: https://readthedocs.org/projects/eth-abi/?badge=latest
.. |PyPi version| image:: https://pypip.in/v/eth-abi/badge.png
:target: https://pypi-hypernode.com/pypi/eth-abi
.. |PyPi downloads| image:: https://pypip.in/d/eth-abi/badge.png
:target: https://pypi-hypernode.com/pypi/eth-ipc-utils
=================
|Build Status| |Documentation Status| |PyPi version| |PyPi downloads|
Python utilities for working with the Ethereum ABI
Installation
------------
.. code:: sh
pip install eth-abi
Documentation
-------------
Decoding
~~~~~~~~
These functions are intended for decoding return values from the EVM.
- ``eth_abi.decode_single(type, data)``
This function tries to decode ``data`` into the python type that
corresponds to the provided ``type``. This function accepts data of type
bytes.
.. code-block:: python
::
>>> decode_single('uint256', b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0009')
12345
The **value** parameter is expected to be one of the recognized EVM
types.
.. note:: This function cannot be used to decode dynamic or array types
such as ``bytes32[]``.
- ``eth_abi.decode_abi(types, data)``
This function decodes ``data`` into the python type corresponding to the
provided ``types``. This function accepts arrays of type byte.
.. code-block:: python
::
>>> decode_abi(['uint256'], b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0009')
[12345]
>>> decode_abi(['bytes32', 'bytes32'], b'a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
['a', 'b']
The **values** parameter is expected to be an iterable whose values are
all one of the recognized EVM types.
Encoding
~~~~~~~~
These functions are intended for encoding python values into
representations that are suitable for interacting with the EVM.
- ``eth_abi.encode_single(type, value)``
This function encodes ``value`` in the ABI encoding for the provided
``type``.
.. code-block:: python
::
>>> encode_single('uint256', 12345)
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0009'
The **value** parameter is expected to be one of the recognized EVM
types.
.. note:: This function cannot be used to encode array types such as
``bytes32[]``.
- ``eth_abi.encode_abi(types, values)``
This function encodes ``values`` in the ABI encoding for the
corresponding type provided by the ``types`` argument.
.. code-block:: python
::
>>> encode_abi(['uint256'], [12345])
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0009'
>>> encode_abi(['bytes32', 'bytes32'], ['a', 'b'])
b'a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
The **values** parameter is expected to be an iterable whose values are
all one of the recognized EVM types.
Development
-----------
Clone the repository and then run:
.. code:: sh
pip install -e . -r requirements-dev.txt
Running the tests
~~~~~~~~~~~~~~~~~
You can run the tests with:
.. code:: sh
py.test tests
Or you can install ``tox`` to run the full test suite.
Releasing
~~~~~~~~~
Pandoc is required for transforming the markdown README to the proper
format to render correctly on pypi.
For Debian-like systems:
::
apt install pandoc
Or on OSX:
.. code:: sh
brew install pandoc
To release a new version:
.. code:: sh
make release bump=$$VERSION_PART_TO_BUMP$$
How to bumpversion
^^^^^^^^^^^^^^^^^^
The version format for this repo is ``{major}.{minor}.{patch}`` for
stable, and ``{major}.{minor}.{patch}-{stage}.{devnum}`` for unstable
(``stage`` can be alpha or beta).
To issue the next version in line, specify which part to bump, like
``make release bump=minor`` or ``make release bump=devnum``.
If you are in a beta version, ``make release bump=stage`` will switch to
a stable.
To issue an unstable version when the current version is stable, specify
the new version explicitly, like
``make release bump="--new-version 4.0.0-alpha.1 devnum"``
.. |Build Status| image:: https://travis-ci.org/ethereum/eth-abi.png
:target: https://travis-ci.org/ethereum/eth-abi
.. |Documentation Status| image:: https://readthedocs.org/projects/eth-abi/badge/?version=latest
:target: https://readthedocs.org/projects/eth-abi/?badge=latest
.. |PyPi version| image:: https://pypip.in/v/eth-abi/badge.png
:target: https://pypi-hypernode.com/pypi/eth-abi
.. |PyPi downloads| image:: https://pypip.in/d/eth-abi/badge.png
:target: https://pypi-hypernode.com/pypi/eth-ipc-utils
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
eth-abi-1.0.0b1.tar.gz
(12.5 kB
view details)
Built Distribution
eth_abi-1.0.0b1-py3-none-any.whl
(14.9 kB
view details)
File details
Details for the file eth-abi-1.0.0b1.tar.gz
.
File metadata
- Download URL: eth-abi-1.0.0b1.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a8bdd71116e525b80677443bd3e02ad5084fa9a3cac693057db1c35f8350354 |
|
MD5 | 4ec9035cc0edf263ba8608ceb6697840 |
|
BLAKE2b-256 | e8535219abf06e8da78be9d405749238c50a7dd9677b16d7dd1d58b9e0e5b821 |
File details
Details for the file eth_abi-1.0.0b1-py3-none-any.whl
.
File metadata
- Download URL: eth_abi-1.0.0b1-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 167c7eb3536570c04aa2ed905ca1ec52baee3b9288402086f08cf85e1c47a381 |
|
MD5 | 9a69dc93a3529af26e7811d91071235f |
|
BLAKE2b-256 | 7e833309dd6af0157cca9a6938f8e95e064267e9bce2013109e4e2c500ea28ab |