Ethereum ABI Utils
Project description
Ethereum Contract
=================
|Build Status| |Documentation Status| |PyPi version|
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://circleci.com/gh/ethereum/eth-abi.svg?style=shield
:target: https://circleci.com/gh/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://img.shields.io/pypi/v/eth-abi.svg
:target: https://pypi-hypernode.com/pypi/eth-abi
=================
|Build Status| |Documentation Status| |PyPi version|
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://circleci.com/gh/ethereum/eth-abi.svg?style=shield
:target: https://circleci.com/gh/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://img.shields.io/pypi/v/eth-abi.svg
:target: https://pypi-hypernode.com/pypi/eth-abi
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.2.1.tar.gz
(19.2 kB
view details)
Built Distribution
eth_abi-1.2.1-py3-none-any.whl
(23.0 kB
view details)
File details
Details for the file eth-abi-1.2.1.tar.gz
.
File metadata
- Download URL: eth-abi-1.2.1.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.18.4 setuptools/36.4.0 requests-toolbelt/0.8.0 tqdm/4.14.0 CPython/2.7.15rc1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4afbe6890554531086682fa27bcdb9192bc80ef812569422eb7022e227a90e2b |
|
MD5 | 23e8170d8d8773d964279da47a5e0f84 |
|
BLAKE2b-256 | e56356d0d7d88f258146a7273e7b312d1e8e7cb6b373a0dce9c3d3dae9edb43f |
File details
Details for the file eth_abi-1.2.1-py3-none-any.whl
.
File metadata
- Download URL: eth_abi-1.2.1-py3-none-any.whl
- Upload date:
- Size: 23.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.18.4 setuptools/36.4.0 requests-toolbelt/0.8.0 tqdm/4.14.0 CPython/2.7.15rc1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 930c68ff30b9d45b7990171180c9356113a214cf1cb857ba51e85e5e6162a673 |
|
MD5 | c14df2d236c4599f062f5bdbe90ed2e8 |
|
BLAKE2b-256 | 9e3fcb60df7c42205a1a3a989d4c9e5f786703b28283dede4384f653ec71f34d |