{"id":13692413,"url":"https://github.com/miguelmota/ethereum-input-data-decoder","last_synced_at":"2025-05-02T19:31:59.024Z","repository":{"id":42187648,"uuid":"83634944","full_name":"miguelmota/ethereum-input-data-decoder","owner":"miguelmota","description":"Ethereum smart contract transaction input data decoder","archived":true,"fork":false,"pushed_at":"2022-07-30T06:48:24.000Z","size":1556,"stargazers_count":607,"open_issues_count":0,"forks_count":192,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-22T08:21:28.571Z","etag":null,"topics":["abi","decoder","ethereum","javascript","library","remix","smart-contracts","solidity","utility"],"latest_commit_sha":null,"homepage":"https://lab.miguelmota.com/ethereum-input-data-decoder","language":"JavaScript","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/miguelmota.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["miguelmota"],"patreon":"miguelmota"}},"created_at":"2017-03-02T04:39:58.000Z","updated_at":"2025-04-11T12:55:50.000Z","dependencies_parsed_at":"2022-08-06T09:00:36.616Z","dependency_job_id":null,"html_url":"https://github.com/miguelmota/ethereum-input-data-decoder","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miguelmota%2Fethereum-input-data-decoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miguelmota%2Fethereum-input-data-decoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miguelmota%2Fethereum-input-data-decoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miguelmota%2Fethereum-input-data-decoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miguelmota","download_url":"https://codeload.github.com/miguelmota/ethereum-input-data-decoder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252095312,"owners_count":21693898,"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":["abi","decoder","ethereum","javascript","library","remix","smart-contracts","solidity","utility"],"created_at":"2024-08-02T17:00:57.676Z","updated_at":"2025-05-02T19:31:58.639Z","avatar_url":"https://github.com/miguelmota.png","language":"JavaScript","funding_links":["https://github.com/sponsors/miguelmota","https://patreon.com/miguelmota"],"categories":["Development"],"sub_categories":[],"readme":"\u003ch3 align=\"center\"\u003e\n  \u003cbr /\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/168240/39537094-61c30484-4ded-11e8-8c93-410ba0510cf4.png\" alt=\"logo\" width=\"750\" /\u003e\n  \u003cbr /\u003e\n  \u003cbr /\u003e\n  \u003cbr /\u003e\n\u003c/h3\u003e\n\n# ethereum-input-data-decoder\n\n\u003e Ethereum smart contract transaction input data decoder\n\n[![License](http://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/miguelmota/ethereum-input-data-decoder/master/LICENSE)\n[![Build Status](https://travis-ci.org/miguelmota/ethereum-input-data-decoder.svg?branch=master)](https://travis-ci.org/miguelmota/ethereum-input-data-decoder)\n[![dependencies Status](https://david-dm.org/miguelmota/ethereum-input-data-decoder/status.svg)](https://david-dm.org/miguelmota/ethereum-input-data-decoder)\n[![NPM version](https://badge.fury.io/js/ethereum-input-data-decoder.svg)](http://badge.fury.io/js/ethereum-input-data-decoder)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](#contributing)\n\n## Demo\n\n[https://lab.miguelmota.com/ethereum-input-data-decoder](https://lab.miguelmota.com/ethereum-input-data-decoder)\n\n## Install\n\n```bash\nnpm install ethereum-input-data-decoder\n```\n\n## Getting started\n\nPass [ABI](https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI) file path to decoder constructor:\n\n```javascript\nconst InputDataDecoder = require('ethereum-input-data-decoder');\nconst decoder = new InputDataDecoder(`${__dirname}/abi.json`);\n```\n\nAlternatively, you can pass ABI array object to constructor;\n\n```javascript\nconst abi = [{ ... }]\nconst decoder = new InputDataDecoder(abi);\n```\n\n[example abi](./test/abi.json)\n\nThen you can decode input data:\n\n```javascript\nconst data = `0x67043cae0000000000000000000000005a9dac9315fdd1c3d13ef8af7fdfeb522db08f020000000000000000000000000000000000000000000000000000000058a20230000000000000000000000000000000000000000000000000000000000040293400000000000000000000000000000000000000000000000000000000000000a0f3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c800000000000000000000000000000000000000000000000000000000000000034254430000000000000000000000000000000000000000000000000000000000`;\n\nconst result = decoder.decodeData(data);\n\nconsole.log(result);\n```\n\n```text\n{\n  \"method\": \"registerOffChainDonation\",\n  \"types\": [\n    \"address\",\n    \"uint256\",\n    \"uint256\",\n    \"string\",\n    \"bytes32\"\n    ],\n    \"inputs\": [\n      \u003cBN: 5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02\u003e,\n      \u003cBN: 58a20230\u003e,\n      \u003cBN: 402934\u003e,\n      \"BTC\",\n      \u003cBuffer f3 df ... 71 c8\u003e\n    ],\n    \"names\": [\n      \"addr\",\n      \"timestamp\",\n      \"chfCents\",\n      \"currency\",\n      \"memo\"\n    ]\n}\n```\n\nExample using input response from [web3.getTransaction](https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethgettransaction):\n\n```javascript\nweb3.eth.getTransaction(txHash, (error, txResult) =\u003e {\n  const result = decoder.decodeData(txResult.input);\n  console.log(result);\n});\n```\n\n### Decoding tuple and tuple[] types\n\nWhere `OrderData` is\n\n```solidity\nstruct OrderData {\n  uint256 amount;\n  address buyer;\n}\n```\n\nDecoding input to a method `someMethod(address,OrderData,OrderData[])` returns data in format\n\n```js\n{\n  method: 'someMethod',\n  types: ['address', '(uint256,address)', '(uint256,address)[]'],\n  inputs: [\n    '0x81c55017F7Ce6E72451cEd49FF7bAB1e3DF64d0C',\n    [100, '0xA37dE6790861B5541b0dAa7d0C0e651F44c6f4D9']\n    [[274, '0xea674fdde714fd979de3edf0f56aa9716b898ec8']]\n  ],\n  names: ['sender', ['order', ['amount', 'buyer']], ['allOrders', ['amount', 'buyer']]]\n}\n```\n\n- In the `types` field, tuples are represented as a string containing types contained in the tuple\n- In the `inputs` field, tuples are represented as an array containing values contained in the tuple\n- In the `names` field, tuples are represented as an array with 2 items. Item 1 is the name of the tuple, item 2 is an array containing the names of the values contained in the tuple.\n\n### Decoding Big Numbers\n\nAll numbers are returned in [big number](https://github.com/indutny/bn.js) format to preserve precision.\n\nHere's an example of how to convert the big number to a human readable format.\n\n```js\nconsole.log(result.inputs[0].toString(10)) // \"5\"\nconsole.log(result.inputs[0].toNumber()) // 55\n```\n\nPlease keep in mind that JavaScript only supports numbers up to 64 bits. Solidity numbers can be up to 256 bits, so you run the risk of truncation when casting or having the big number library error out when trying to parse a large number to a JavaScript Number type.\n\n```js\nconst n = new BN(\"543534254523452352345234523455\")\nconsole.log(n.toString(10)) // \"543534254523452352345234523455\"\nconsole.log(n.toNumber()) // ERROR!\n```\n\n## CLI\n\n## Install\n\n```bash\nnpm install -g ethereum-input-data-decoder\n```\n\n### Usage\n\n```bash\n$ ethereum_input_data_decoder --help\n\n  Ethereum smart contract transaction input data decoder\n\n  Usage\n    $ ethereum_input_data_decoder [flags] [input]\n\n  Options\n    --abi, -a  ABI file path\n    --input, -i Input data file path\n\n  Examples\n    $ ethereum_input_data_decoder --abi token.abi --input data.txt\n    $ ethereum_input_data_decoder --abi token.abi \"0x23b872dd...\"\n```\n\n### Example\n\nPass ABI file and input data as file:\n\n```bash\n$ ethereum_input_data_decoder --abi abi.json --input data.tx\n\nmethod   registerOffChainDonation\n\naddress  addr       0x5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02\nuint256  timestamp  1487012400\nuint256  chfCents   4204852\nstring   currency   BTC\nbytes32  memo       0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8\n```\n\nPass ABI file and input data as string:\n\n```bash\n$ ethereum_input_data_decoder --abi abi.json 0x67043cae0...000000\n\nmethod   registerOffChainDonation\n\naddress  addr       0x5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02\nuint256  timestamp  1487012400\nuint256  chfCents   4204852\nstring   currency   BTC\nbytes32  memo       0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8\n```\n\nYou can also pipe the input data:\n\n```bash\n$ cat data.txt | ethereum_input_data_decoder --abi abi.json\n\nmethod   registerOffChainDonation\n\naddress  addr       0x5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02\nuint256  timestamp  1487012400\nuint256  chfCents   4204852\nstring   currency   BTC\nbytes32  memo       0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8\n```\n\n## Test\n\n```bash\nnpm test\n```\n\n## Development\n\n1. Clone repository:\n\n  ```bash\n  git clone git@github.com:miguelmota/ethereum-input-data-decoder.git\n\n  cd ethereum-input-data-decoder/\n  ```\n\n2. Install dependencies:\n\n  ```bash\n  npm install\n  ```\n\n3. Make changes.\n\n4. Run tests:\n\n  ```bash\n  npm test\n  ```\n\n5. Run linter:\n\n  ```bash\n  npm run lint\n  ```\n\n5. Build:\n\n  ```bash\n  npm run build\n  ```\n\n## Contributing\n\nPull requests are welcome!\n\nFor contributions please create a new branch and submit a pull request for review.\n\nMany thanks to all the [contributors](https://github.com/miguelmota/ethereum-input-data-decoder/graphs/contributors) for making this a better library for everyone 🙏\n\n## FAQ\n\n- Q: How can I retrieve the ABI?\n\n  - A: You can generate the ABI from the solidity source files using the [Solidity Compiler](http://solidity.readthedocs.io/en/develop/installing-solidity.html).\n\n    ```bash\n    solc --abi MyContract.sol -o build\n    ```\n\n- Q: Can this library decode contract creation input data?\n\n  - A: Yes, it can decode contract creation input data.\n\n- Q: Does this library support ABIEncoderV2?\n\n  - A: Yes, but it's buggy. Please submit a [bug report](https://github.com/miguelmota/ethereum-input-data-decoder/issues/new) if you encounter issues.\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiguelmota%2Fethereum-input-data-decoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiguelmota%2Fethereum-input-data-decoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiguelmota%2Fethereum-input-data-decoder/lists"}