{"id":19303807,"url":"https://github.com/web3w/web3-abi-coder","last_synced_at":"2025-04-22T11:32:15.120Z","repository":{"id":111890606,"uuid":"504432440","full_name":"web3w/web3-abi-coder","owner":"web3w","description":"The best ABI Coder tool","archived":false,"fork":false,"pushed_at":"2023-11-05T14:54:07.000Z","size":6058,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-13T03:50:10.094Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/web3w.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":"2022-06-17T07:16:23.000Z","updated_at":"2022-09-06T10:16:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"d31fd0bc-c4b9-49b6-bb93-3f0d7cd93372","html_url":"https://github.com/web3w/web3-abi-coder","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web3w%2Fweb3-abi-coder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web3w%2Fweb3-abi-coder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web3w%2Fweb3-abi-coder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web3w%2Fweb3-abi-coder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/web3w","download_url":"https://codeload.github.com/web3w/web3-abi-coder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250232215,"owners_count":21396595,"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-09T23:27:38.448Z","updated_at":"2025-04-22T11:32:10.222Z","avatar_url":"https://github.com/web3w.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Web3 ABI Coder\n\nUtils that encodes and decodes transactions and logs for evm.\n\n\u003chttps://web3w.github.io/web3-abi-coder/\u003e\n\n## Motivation\n\nTo solve the problem of unreadable web3.js and Ethers decoder data.\n\n## Features\n\n* Readable result\n* Input data decode\n* Logs decode\n* ERC20Coder,ERC721Coder, ERC1155Coder\n* Block tx decode\n* Receipt decode\n\n## Installation\n\n`npm i web3-abi-coder`\n\n## Example\n\n### decodeBlock\n\n```ts\nimport {\n    ERC1155ABI, ERC721ABI, ERC20Coder,\n    getBlockByNumber, getTransactionByHash, getTransactionReceipt\n} from 'web3-abi-coder';\nimport Seaport from \"./abi/Seaport.json\"\n\nconst blockNum = 10862111 //\"0xa5be1f\"\nconst coder = ERC20Coder.addABI(ERC721ABI).addABI(ERC1155ABI).addABI(Seaport.abi)\nconst {result: block} = await getBlockByNumber(blockNum)\nconsole.log(coder.decodeBlock(block))\n/*\n[\n  {\n    name: 'approve',\n    type: 'function',\n    values: {\n      spender: '0xf2450ae4A2FEdC654C48f5FC1FdF596D05007761',\n      amount: '200000000000000000000'\n    },\n    hash: '0x7f6c78ecac73137076d10429905c5c45b47bde030035f614601a3a1983c2e822'\n  },\n  {\n    name: 'fulfillAdvancedOrder',\n    type: 'function',\n    values: {\n      advancedOrder: [Object],\n      criteriaResolvers: [],\n      fulfillerConduitKey: '0x0000000000000000000000000000000000000000000000000000000000000000',\n      recipient: '0xcBE352f2559fe4209DDa6Ee2779cE254d2347d91'\n    },\n    hash: '0xbfe24528d5e90822924687d28d55dc492a65660d205c5619d8116780c69497f6'\n  },\n  ...\n]\n* */\n```\n\n### decodeTransaction\n\n```ts\nconst txHash = \"0xbfe24528d5e90822924687d28d55dc492a65660d205c5619d8116780c69497f6\"\nconst txData = await getTransactionByHash(txHash)\nconst decodeData = seaportCoder.decodeTransaction(txData.result)\n/*{\n  \"name\": \"fulfillAdvancedOrder\",\n  \"type\": \"function\",\n  \"values\": {\n    \"advancedOrder\": {\n      \"parameters\": {\n        \"offerer\": \"0x9226f7dF5E316df051F0490cE3b753c51695D0Bb\",\n        \"zone\": \"0x00000000E88FE2628EbC5DA81d2b3CeaD633E89e\",\n        \"offer\": [\n          {\n            \"itemType\": 2,\n            \"token\": \"0x1878AaD5E60704f3DEc1F46bcFbf632055FCDD18\",\n            \"identifierOrCriteria\": \"1\",\n            \"startAmount\": \"1\",\n            \"endAmount\": \"1\"\n          }\n        ]..\n      }..\n    }\n    ....\n}\n*/\n```\n\n### decodeTransactionReceipt\n\n```ts\nconst txHash = \"0xbfe24528d5e90822924687d28d55dc492a65660d205c5619d8116780c69497f6\"\nconst coder = ERC20Coder.addABI(ERC721ABI).addABI(ERC1155ABI).addABI(Seaport.abi)\nconst {result: receipt} = await getTransactionReceipt(txHash)\nconsole.log(coder.decodeTransactionReceipt(receipt))\n/*[\n  {\n    name: 'Transfer',\n    type: 'event',\n    values: {\n      from: '0x9226f7dF5E316df051F0490cE3b753c51695D0Bb',\n      to: '0xcBE352f2559fe4209DDa6Ee2779cE254d2347d91',\n      amount: '1'\n    },\n    hash: '0xbfe24528d5e90822924687d28d55dc492a65660d205c5619d8116780c69497f6'\n  },\n  {\n    name: 'OrderFulfilled',\n    type: 'event',\n    values: {\n      orderHash: '0xf9fc6150b8befdda825b0e6bdd8723105e010b32c67b1c2f9fc5b053d55b3d70',\n      offerer: '0x9226f7dF5E316df051F0490cE3b753c51695D0Bb',\n      zone: '0x00000000E88FE2628EbC5DA81d2b3CeaD633E89e',\n      recipient: '0xcBE352f2559fe4209DDa6Ee2779cE254d2347d91',\n      offer: [Array],\n      consideration: [Array]\n    },\n    hash: '0xbfe24528d5e90822924687d28d55dc492a65660d205c5619d8116780c69497f6'\n  }\n]\n*/\n```\n\n### decodeInput\n\n```ts\nimport Web3ABICoder,{ ERC20Coder} from 'web3-abi-coder';\nimport Seaport from \"./abi/Seaport.json\"\n\nconst seaCoder = new Web3ABICoder(Seaport.abi)\nconst inputData = seaCoder.encodeInput(\"getCounter\", [\"0x0A56b3317eD60dC4E1027A63ffbE9df6fb102401\"])\nconst func = seaCoder.getFunctionName(inputData.substring(0, 10))\nconst decodeData = seaCoder.decodeInput(inputData)\n/*\n{\n  name: 'getCounter',\n  type: 'function',\n  values: { offerer: '0x0A56b3317eD60dC4E1027A63ffbE9df6fb102401' }\n}\n\n*/\n```\n\n### decodeLog\n\n```ts\n\nconst erc20Log = {\n    data: \"0x0000000000000000000000000000000000000000000000370c9b5ef669c35300\",\n    topics: [\n        '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n        '0x000000000000000000000000b5cfcb4d4745cbbd252945856e1b6eaadcf2fc4e',\n        '0x000000000000000000000000694c6aea9444876d4fa9375fc9089c370f8e9eda',\n    ]\n}\nconst erc20LogData = ERC20Coder.decodeLog(erc20Log)\nconsole.log(erc20LogData)\n/*\n{\n  name: 'Transfer',\n  type: 'event',\n  values: {\n    from: '0xb5CFcb4D4745cBBD252945856E1B6eaadCf2fC4E',\n    to: '0x694c6aea9444876d4fA9375fC9089C370F8E9edA',\n    value: '1015479348216300000000'\n  }\n}\n*/ \n```\n\n### encodeInput\n\n```ts\n\nconst transferCallData = ERC20Coder.encodeInput(\"transfer\", [\"0xad47d554e3a527d5cb4712b79eabba4f6152abcd\", \"2\"])\nconst transferValue = ERC20Coder.decodeInput(transferCallData)\nconsole.log(transferValue)\n/*\n{ \n    name: 'transfer',\n    type: 'function',\n    values: { to: '0xAD47D554E3A527D5Cb4712B79EaBBA4f6152abCd', amount: '2' }\n}\n*/\n```\n\n## API\n\n* Web3ABICoder(abi) extends Interface\n  * abi\n    * ERC20ABI,ERC721,ERC1155\n    * addABI(abi: ReadonlyArray\u003cFragment | JsonFragment\u003e): Web3ABICoder\n    * ...abiCoder\n  * utils\n    * getFunctionName(sighash: string):string\n    * getFunctionSelector(name: string): { name: string, signature: string, sighash: string }[]\n    * getFunctionSelectors(): { name: string, signature: string, sighash: string }[]\n    * getFunctionSignature(name: string, type?: \"minimal\" | \"json\" | \"full\"): string[]\n    * getEvent(nameOrSignatureOrTopic: string): EventFragment\n    * getEvents(): { name: string, signature: string, topic: string }\n    * ...Interface\n  * decoding\n    * decodeBlock\u003cT\u003e(block): DecodeResult\u003cT\u003e[]\n    * decodeTransaction\u003cT\u003e(transaction): DecodeResult\u003cT\u003e[]\n    * decodeTransactionReceipt\u003cT\u003e(receipt): DecodeResult\u003cT\u003e[]\n    * decodeConstructor\u003cT\u003e(data: string): DecodeResult\u003cT\u003e\n    * decodeInput\u003cT\u003e(inputData: string): DecodeResult\u003cT\u003e\n    * decodeInputParams(funcName, inputCode)\n    * decodeLog\u003cT\u003e(log: { topics: string[], data: string }): DecodeResult\u003cT\u003e\n    * decodeOutput\u003cT\u003e(nameOrSighash: string, outputData: string): DecodeResult\u003cT\u003e\n    * ...Interface\n  * encoding\n    * encodeInput(nameOrSighash: string, inputs: any[])\n    * ...Interface\n  * utils\n    * get4Bytes\n    * getTransferEvents\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweb3w%2Fweb3-abi-coder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweb3w%2Fweb3-abi-coder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweb3w%2Fweb3-abi-coder/lists"}