{"id":18738084,"url":"https://github.com/blocknative/ethereum-input-decoder","last_synced_at":"2025-04-12T19:32:45.013Z","repository":{"id":49426782,"uuid":"355022133","full_name":"blocknative/ethereum-input-decoder","owner":"blocknative","description":null,"archived":false,"fork":false,"pushed_at":"2023-04-12T03:50:49.000Z","size":12449,"stargazers_count":13,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T14:05:51.694Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blocknative.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-04-06T01:36:23.000Z","updated_at":"2024-07-09T09:48:12.000Z","dependencies_parsed_at":"2024-11-07T15:37:02.522Z","dependency_job_id":"1ed78f3c-682a-4a7b-b1bd-b929287c44fe","html_url":"https://github.com/blocknative/ethereum-input-decoder","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknative%2Fethereum-input-decoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknative%2Fethereum-input-decoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknative%2Fethereum-input-decoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknative%2Fethereum-input-decoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blocknative","download_url":"https://codeload.github.com/blocknative/ethereum-input-decoder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248621382,"owners_count":21134829,"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":[],"created_at":"2024-11-07T15:28:07.629Z","updated_at":"2025-04-12T19:32:44.726Z","avatar_url":"https://github.com/blocknative.png","language":"TypeScript","readme":"# ethereum-input-decoder\n\nDecodes an Ethereum input data hex string into a developer friendly JavaScript object. Optionally can be translated into an object which includes Solidity types.\n\n## Warning\n\nThis package is in alpha, use at your own risk!\n\n## Aim\n\nThe goal of ethereum-input-decoder is to facilitate dead-simple conversion of a transaction input into a JavaScript native, serializable object.\n\n## Usage\n\n### Creating a specific decoder object for decoding reuse\n\nHere we create an instance of a decoder using a given ABI, to which we can decode inputs with.\nWe are also able to choose the output format for decoding in this instance.\n\n```javascript\nimport InputDataDecoder = from 'ethereum-input-decoder'\nconst erc20Abi = [{ ... }]\nconst erc20Decoder = new InputDataDecoder(erc20Abi)\nconst transferInput = '0xa9059cb000...'\nconst result = erc20Decoder.decodeData(transferInput)\nconsole.log(result)\n```\n```javascript\n{\n  methodName: 'transfer',\n  params: {\n    _to: '0x5A1Cb5A88988cA4FEF229935db834A6781e873cB',\n    _value: '1000000000000000000'\n  }\n}\n```\n\nThe `InputDataDecoder` can take a second argument detailing the requested output format.\n\n```javascript\nconst erc20Decoder = new InputDataDecoder(erc20Abi, 'solidityTypes') // default is 'jsObject'\nconst result = erc20Decoder.decodeData(transferInput)\nconsole.log(result)\n```\n```javascript\n// solidityTypes format\n{\n      methodName: 'transfer',\n      params: [\n        {\n          name: '_to',\n          type: 'address',\n          value: '0x5A1Cb5A88988cA4FEF229935db834A6781e873cB',\n        },\n        {\n          name: '_value',\n          type: 'uint256',\n          value: '1000000000000000000',\n        },\n      ],\n    }\n```\n\n### Passing both the ABI and the input together\n\nHere we pass `decodeInput` both an ABI and an input to receive the decoded output in 'jsObject' format.\nThis creates the decoder instance each call, it would be recommended to make a decoder instance for each contract\nfor multiple calls.\n\n```javascript\nimport decodeInput from 'ethereum-input-decoder'\nconst erc20Abi = [{ ... }] // this may be an ABI object or an InputDataDecoder instance as above\nconst transferInput = '0xa9059cb000...'\nconst result = decodeInput(erc20Abi, transferInput)\n```\n\n### Unable to decode example\n\nIf the input does not match the ABI, both `decodeInput` and `InputDataDecoder.decodeData()` returns `null`\n\n```javascript\nimport decodeInput from 'ethereum-input-decoder'\nconst erc20Abi = [{ ... }]\nconst failingData = '0xbitconnect'\nconst result = decoder.decodeData(failingData)\nconsole.log(result)\n```\n```javascript\nnull\n```\n\n### Usage in node.js\n\nWhen ES6 imports are not available, you may use `require`\n\n```javascript\nconst inputToObject = require('ethereum-input-decoder')\n```\n\n### Supported types\n\n| Solidity | JavaScript equivalent used\n|------|--------|\n| int (all variations) | String\n| address | String\n| string | String\n| bool | Boolean\n| bytes (all variations) | String (hex formatted)\n| tuple | Object (with contents also converted)\n| array | Array (with contents also converted)\n\nUsing a type not supported? Open an issue.\n\n## Precursor work acknowledgement \n\nThis library is inspired by the great work by Miguel on [ethereum-input-data-decoder](https://github.com/miguelmota/ethereum-input-data-decoder), and fellow Blocknative dev Liam on [ethereum-input-to-object](https://github.com/blocknative/ethereum-input-to-object)\n\n## Todo list\n- Ensure contract constructor is decoded\n- Add extensive fuzzing testing (maybe)\n- Have an available format that does not decode the solidity values at all, ie does not call `parseCallValue()`\n- Add error throwing [ 'no matching function', 'incorrect inputs', ... ]\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblocknative%2Fethereum-input-decoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblocknative%2Fethereum-input-decoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblocknative%2Fethereum-input-decoder/lists"}