{"id":16469402,"url":"https://github.com/kigawas/web3-input-decoder","last_synced_at":"2025-04-05T10:07:11.143Z","repository":{"id":38318292,"uuid":"351375216","full_name":"kigawas/web3-input-decoder","owner":"kigawas","description":"A simple offline web3 transaction input decoder for functions and constructors.","archived":false,"fork":false,"pushed_at":"2025-03-23T10:49:20.000Z","size":517,"stargazers_count":52,"open_issues_count":3,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T09:08:25.111Z","etag":null,"topics":["ethereum","web3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kigawas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-25T09:18:28.000Z","updated_at":"2025-03-23T10:47:56.000Z","dependencies_parsed_at":"2023-02-10T04:45:17.093Z","dependency_job_id":"faf91d07-31b4-44d2-a3b0-7f5fb4d31548","html_url":"https://github.com/kigawas/web3-input-decoder","commit_stats":{"total_commits":103,"total_committers":3,"mean_commits":"34.333333333333336","dds":"0.35922330097087374","last_synced_commit":"415d5f1785705d913fd58be7fcd00da28fb6afdc"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kigawas%2Fweb3-input-decoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kigawas%2Fweb3-input-decoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kigawas%2Fweb3-input-decoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kigawas%2Fweb3-input-decoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kigawas","download_url":"https://codeload.github.com/kigawas/web3-input-decoder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247318744,"owners_count":20919484,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ethereum","web3"],"created_at":"2024-10-11T12:07:19.140Z","updated_at":"2025-04-05T10:07:11.116Z","avatar_url":"https://github.com/kigawas.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# web3-input-decoder\n\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/6f10d5104ef4464797ee94b17c7b9371)](https://www.codacy.com/gh/kigawas/web3-input-decoder/dashboard)\n[![CI](https://img.shields.io/github/actions/workflow/status/kigawas/web3-input-decoder/ci.yml)](https://github.com/kigawas/web3-input-decoder/actions)\n[![Codecov](https://img.shields.io/codecov/c/github/kigawas/web3-input-decoder.svg)](https://codecov.io/gh/kigawas/web3-input-decoder)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/web3-input-decoder.svg)](https://pypi.org/project/web3-input-decoder/)\n[![PyPI](https://img.shields.io/pypi/v/web3-input-decoder.svg)](https://pypi.org/project/web3-input-decoder/)\n[![License](https://img.shields.io/github/license/kigawas/web3-input-decoder.svg)](https://github.com/kigawas/web3-input-decoder)\n\nA simple offline web3 transaction input decoder for functions and constructors.\n\n## Install\n\n```bash\npip install web3-input-decoder\n```\n\n## Quick start\n\nLet's take a [USDT transfer transaction](https://etherscan.io/tx/0x0331fdfa070ee26b1fc7b01b246ef5e58593cbe9f4a02f7f09bf4a2aa640cf35) and the [USDT contract creator transaction](https://etherscan.io/address/0xdac17f958d2ee523a2206206994597c13d831ec7#code) as an example:\n\n```python\n\u003e\u003e\u003e import json\n\u003e\u003e\u003e import urllib.request\n\u003e\u003e\u003e from web3_input_decoder import decode_constructor, decode_function\n\u003e\u003e\u003e f = urllib.request.urlopen(\"https://api.etherscan.io/api?module=contract\u0026action=getabi\u0026address=0xdac17f958d2ee523a2206206994597c13d831ec7\")\n\u003e\u003e\u003e TETHER_ABI = json.loads(json.load(f)[\"result\"])\n\u003e\u003e\u003e decode_function(\n        TETHER_ABI, \"0xa9059cbb000000000000000000000000f050227be1a7ce587aa83d5013f900dbc3be0611000000000000000000000000000000000000000000000000000000000ecdd350\",\n    )\n[('address', '_to', '0xf050227be1a7ce587aa83d5013f900dbc3be0611'),\n ('uint256', '_value', 248370000)]\n\u003e\u003e\u003e decode_constructor(\n        TETHER_ABI, \"000000000000000000000000000000000000000000000000000000174876e800000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a546574686572205553440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000045553445400000000000000000000000000000000000000000000000000000000\"\n    )\n[('uint256', '_initialSupply', 100000000000),\n ('string', '_name', 'Tether USD'),\n ('string', '_symbol', 'USDT'),\n ('uint256', '_decimals', 6)]\n```\n\nYou can also play with it [here](https://replit.com/@kigawas/Web3-input-decoder-quick-start).\n\n### Performance enhancement\n\nIf you have lots of inputs in the same contract to decode, consider using [`InputDecoder`](web3_input_decoder/decoder.py#L41).\n\n```python\n\u003e\u003e\u003e from web3_input_decoder import InputDecoder\n\u003e\u003e\u003e decoder = InputDecoder(TETHER_ABI)\n\u003e\u003e\u003e for _ in range(10000):\n\u003e\u003e\u003e    decoder.decode_function(\n          (\n            \"0xa9059cbb000000000000000000000000f050227be1a7ce587aa83d5013f900dbc3b\"\n            \"e0611000000000000000000000000000000000000000000000000000000000ecdd350\"\n          ),\n        )\n```\n\n## API\n\n- [`decode_constructor`](web3_input_decoder/__init__.py#L12)\n\n  ```python\n  def decode_constructor(\n      abi: List[dict],\n      tx_input: Union[str, bytes],\n      bytecode: Optional[Union[str, bytes]] = None,\n  ) -\u003e List[Tuple[str, str, Any]]\n  ```\n\n  **Parameters**:\n\n  - `abi`: Contract ABI\n  - `tx_input`: Transaction input to decode, with or without deployed contract bytecode\n  - `bytecode`: Optional deployed contract bytecode. If this is set, `tx_input` should include bytecode\n\n  **Returns**:\n\n  - `List[Tuple[str, str, Any]]`: Decoded type-name-value tuples\n\n- [`decode_function`](web3_input_decoder/__init__.py#L37)\n\n  ```python\n  def decode_function(\n      abi: List[dict], tx_input: Union[str, bytes]\n  ) -\u003e List[Tuple[str, str, Any]]\n  ```\n\n  **Parameters**:\n\n  - `abi`: Contract ABI\n  - `tx_input`: Transaction input to decode\n\n  **Returns**:\n\n  - `List[Tuple[str, str, Any]]`: Decoded type-name-value tuples\n\n## Rationale\n\nExisting solutions are not satisfying to me, e.g.:\n\n1. [web3py](https://web3py.readthedocs.io/en/latest/web3.contract.html#web3.contract.Contract.decode_function_input) can only decode function calls and it's necessary to be online to set up a provider first.\n2. [ethereum-input-decoder](https://github.com/tintinweb/ethereum-input-decoder) is not maintained and it contains several glitches.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkigawas%2Fweb3-input-decoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkigawas%2Fweb3-input-decoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkigawas%2Fweb3-input-decoder/lists"}