├── .gitignore ├── data ├── bytecodes │ ├── MintableNFT.json │ └── EnclavesDEXProxy.json └── abis │ ├── EnclavesDEXProxy.json │ └── MintableNFT.json ├── package.json ├── LICENSE.md ├── scripts └── endecodeHelper.js ├── index.js ├── README.md └── test └── index.test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /data/bytecodes/MintableNFT.json: -------------------------------------------------------------------------------- 1 | { 2 | "constructor-bytecode": "000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000f4578706572696d656e74616c4e4654000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000066531316e66740000000000000000000000000000000000000000000000000000" 3 | } 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "canoe-solidity", 3 | "version": "0.1.0", 4 | "description": "", 5 | "main": "index.js", 6 | "dependencies": { 7 | "ethereumjs-abi": "^0.6.5", 8 | "ethereumjs-util": "^5.2.0", 9 | "underscore": "^1.9.1" 10 | }, 11 | "devDependencies": { 12 | "chai": "^4.1.2", 13 | "jsdoc-to-markdown": "^4.0.1", 14 | "mocha": "^5.2.0" 15 | }, 16 | "scripts": { 17 | "test": "mocha", 18 | "docs": "jsdoc2md index.js | sed 's/^#/##/g'" 19 | }, 20 | "homepage": "https://github.com/cryptofinlabs/canoe-solidity", 21 | "author": "dmdque", 22 | "license": "ISC" 23 | } 24 | -------------------------------------------------------------------------------- /data/bytecodes/EnclavesDEXProxy.json: -------------------------------------------------------------------------------- 1 | { 2 | "constructor-bytecode": "000000000000000000000000129caf12c70fe9633fe24b15497adafc913c842c000000000000000000000000ed06d46ffb309128c4458a270c99c824dc127f5d000000000000000000000000e03793e63776cf69fe42414ed03bb924d4d9157e000000000000000000000000e03793e63776cf69fe42414ed03bb924d4d9157e00000000000000000000000000000000000000000000000000071afd498d0000000000000000000000000000000000000000000000000000016345785d8a00000000000000000000000000008d12a197cb00d4747a1fe03395095ce2a5cc681957d54158692b43b05f55462695c3dc04b0217afddfda3f27a07ec31ee46b9c20369521fb20e3cff93d515dad43dc9f9f23dfdbb8d0ca564c480634d401bf9aa1" 3 | } 4 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2018 CryptoFin 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /scripts/endecodeHelper.js: -------------------------------------------------------------------------------- 1 | let { decodeConstructorArgs, encodeConstructorArgs } = require('./index.js'); 2 | 3 | const ENCODE = true; 4 | 5 | /** 6 | * ENCODE 7 | */ 8 | 9 | let inputs = [ 10 | { 11 | 'name': 'addresses', 12 | 'type': 'address[]', 13 | 'data': ['0xffffffffffffffffffffffffffffffffffffffff', '0xF1E48f13768bD8114A530070b43257a63f24bb12'] 14 | }, 15 | { 16 | 'name': 'bytes32s', 17 | 'type': 'bytes32[]', 18 | 'data': ['0xffffffffffffffffffffffffffffffffffffffff', '0xF1E48f13768bD8114A530070b43257a63f24bb12', '0xcccccccccccccccccccccccccccccccccccccccc'] 19 | }, 20 | { 21 | 'name': 'bytes4s', 22 | 'type': 'bytes4[]', 23 | 'data': ['0xff', '0xF1E48f13'] 24 | }, 25 | { 26 | 'name': 'strings', 27 | 'type': 'string[]', 28 | 'data': ['0xaa', '0xbb', '0xcc', '0xdd'] 29 | }, 30 | { 31 | 'name': 'bytes', 32 | 'type': 'bytes', 33 | 'data': ['0xaa', '0xbb', '0xcc', '0xdd'] 34 | } 35 | ]; 36 | 37 | if (ENCODE) { 38 | const result = encodeConstructorArgs(inputs); 39 | console.log('encodeConstructorArgs result', result); 40 | const words = splitWords256(result); 41 | console.log('words', words); 42 | } 43 | 44 | function splitWords256(bytecode) { 45 | let words = []; 46 | for(let i = 0; i < bytecode.length / 64; i++) { 47 | words.push(bytecode.substring(64 * i, 64 * (i + 1))); 48 | } 49 | return words; 50 | } 51 | 52 | /** 53 | * DECODE 54 | */ 55 | 56 | let BsktTokenABIMock = { 57 | 'abi': [ 58 | { 59 | 'inputs': [ 60 | { 61 | 'name': 'addresses', 62 | 'type': 'address[]' 63 | }, 64 | { 65 | 'name': 'quantities', 66 | 'type': 'uint256[]' 67 | }, 68 | { 69 | 'name': '_creationUnit', 70 | 'type': 'uint256' 71 | }, 72 | { 73 | 'name': '_name', 74 | 'type': 'string' 75 | }, 76 | { 77 | 'name': '_symbol', 78 | 'type': 'string' 79 | } 80 | ], 81 | 'payable': false, 82 | 'stateMutability': 'nonpayable', 83 | 'type': 'constructor' 84 | } 85 | ] 86 | }; 87 | 88 | let abiMock = { 89 | 'abi': [ 90 | { 91 | 'anonymous': false, 92 | 'inputs': inputs, 93 | 'payable': false, 94 | 'stateMutability': 'nonpayable', 95 | 'type': 'constructor' 96 | } 97 | ] 98 | }; 99 | let bytecodeMock = '00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000008ac7230489e80000000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000ffffffffffffffffffffffffffffffffffffffff000000000000000000000000f1e48f13768bd8114a530070b43257a63f24bb1200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000012457468657265756d31302051322d32303138000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034531300000000000000000000000000000000000000000000000000000000000'; 100 | 101 | if (!ENCODE) { 102 | let result = decodeConstructorArgs(abiMock.abi, bytecodeMock); 103 | console.log('decodeConstructorArgs result', result); 104 | } 105 | -------------------------------------------------------------------------------- /data/abis/EnclavesDEXProxy.json: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"bytes32"}],"name":"orderFills","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"etherDeltaInfo","outputs":[{"name":"feeMake","type":"uint256"},{"name":"feeTake","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"proposedTimestamp","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"tokens","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"feeAmountThreshold","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"useEIP712","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"keyValueStorage","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"feeAccount","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tradeABIHash","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getImplementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"proposedImplementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"bytes32"}],"name":"orders","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"feeTake","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_proposedImplementation","type":"address"}],"name":"proposeUpgrade","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"upgrade","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"etherDelta","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"admin","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"withdrawABIHash","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_storageAddress","type":"address"},{"name":"_implementation","type":"address"},{"name":"_admin","type":"address"},{"name":"_feeAccount","type":"address"},{"name":"_feeTake","type":"uint256"},{"name":"_feeAmountThreshold","type":"uint256"},{"name":"_etherDelta","type":"address"},{"name":"_tradeABIHash","type":"bytes32"},{"name":"_withdrawABIHash","type":"bytes32"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_proposedImplementation","type":"address"},{"indexed":false,"name":"_proposedTimestamp","type":"uint256"}],"name":"UpgradedProposed","type":"event"}] 2 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | let utils = require('ethereumjs-util'); 2 | let abi = require('ethereumjs-abi'); 3 | let _ = require('underscore'); 4 | 5 | function isArray(type) { 6 | return type.lastIndexOf(']') === type.length - 1; 7 | } 8 | 9 | function getElementType(type) { 10 | const i = type.lastIndexOf('['); 11 | return type.substring(0, i); 12 | } 13 | 14 | function formatSingle(type, data) { 15 | let decodedData; 16 | if (isArray(type)) { 17 | // TODO: handle each array appropriately 18 | const elementType = getElementType(type); 19 | decodedData = _.map(data, function(data) { 20 | return formatSingle(elementType, data); 21 | }); 22 | } else if (type.includes('bytes')) { 23 | const dataBuffer = Buffer.from(data, 'utf8'); 24 | decodedData = dataBuffer.toString('hex'); 25 | } else { 26 | decodedData = data.toString(); 27 | } 28 | return decodedData; 29 | } 30 | 31 | /** 32 | * Decodes constructor args. 33 | * 34 | * @param {Object} contractABI - ABI of contract whose args to decode 35 | * @param {string} bytecode - Constructor args bytecode 36 | * @returns {Object} decodedArgs - Object representing decoded args with name, type, and data fields 37 | */ 38 | function decodeConstructorArgs(contractABI, bytecode) { 39 | const constructor = _.findWhere(contractABI, { 'type': 'constructor'}); 40 | const inputNames = _.pluck(constructor.inputs, 'name'); 41 | const inputTypes = _.pluck(constructor.inputs, 'type'); 42 | let decoded = abi.rawDecode(inputTypes, new Buffer(bytecode, 'hex')); 43 | let decodedArgs = _.map(decoded, function(e, i) { 44 | const data = formatSingle(inputTypes[i], e); 45 | return { 'name': inputNames[i], 'type': inputTypes[i], 'data': data }; 46 | }); 47 | return decodedArgs; 48 | } 49 | 50 | /** 51 | * Generates constructor args bytecode based on input data. 52 | * 53 | * @param {Object[]} inputs - Array of objects with name, and type fields 54 | * @param {string} inputs[].name - Name of argument 55 | * @param {string} inputs[].type - Type of argument 56 | * @returns {string} bytecode - Constructor args bytecode 57 | */ 58 | function encodeConstructorArgs(inputs) { 59 | const inputTypes = _.pluck(inputs, 'type') 60 | const args = _.pluck(inputs, 'data') 61 | const encoded = abi.rawEncode(inputTypes, args); 62 | const bytecode = encoded.toString('hex'); 63 | return bytecode; 64 | } 65 | 66 | /** 67 | * Decodes function args. 68 | * 69 | * @param {Object} contractABI - ABI of contract whose args to decode 70 | * @param {string} bytecode - full call args bytecode 71 | * @returns {Object} decodedArgs - Object representing decoded args with name, type, and data fields 72 | */ 73 | function decodeFunctionArgs(contractABI, bytecode) { 74 | const argsBuffer = new Buffer(bytecode, 'hex'); 75 | const methodID = argsBuffer.slice(0, 4); 76 | const argsData = argsBuffer.slice(4); 77 | const func = _.find(contractABI, function(o) { 78 | if (o.type === 'function') { 79 | const inputTypes = _.pluck(o.inputs, 'type'); 80 | return methodID.equals(abi.methodID(o.name, inputTypes)); 81 | } 82 | return false; 83 | }); 84 | 85 | if (!func) { 86 | return null; 87 | } 88 | 89 | const inputNames = _.pluck(func.inputs, 'name'); 90 | const inputTypes = _.pluck(func.inputs, 'type'); 91 | let decoded = abi.rawDecode(inputTypes, argsData); 92 | let decodedArgs = _.map(decoded, function(e, i) { 93 | const data = formatSingle(inputTypes[i], e); 94 | return { 'name': inputNames[i], 'type': inputTypes[i], 'data': data }; 95 | }); 96 | return decodedArgs; 97 | } 98 | 99 | module.exports = { 100 | decodeConstructorArgs: decodeConstructorArgs, 101 | encodeConstructorArgs: encodeConstructorArgs, 102 | decodeFunctionArgs: decodeFunctionArgs 103 | }; 104 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🛶 Canoe Solidity 2 | Lightweight Javascript library for decoding constructor arguments. 3 | 4 | ## Summary 5 | Canoe works by reading a contract's ABI and decoding the constructor bytecode with the argument types provided. 6 | 7 | ## Install 8 | 9 | npm install canoe-solidity 10 | 11 | ## Requirements 12 | - ABI schema 2.0 13 | 14 | ## Documentation 15 | ### Functions 16 | 17 |
ObjectDecodes constructor args.
20 |stringGenerates constructor args bytecode based on input data.
23 |ObjectDecodes function call args.
26 |Object
32 | Decodes constructor args.
33 |
34 | **Kind**: global function
35 | **Returns**: Object - decodedArgs - Object representing decoded args with name, type, and data fields
36 |
37 | | Param | Type | Description |
38 | | --- | --- | --- |
39 | | contractABI | Object | ABI of contract whose args to decode |
40 | | bytecode | string | Constructor args bytecode |
41 |
42 |
43 |
44 | ### encodeConstructorArgs(inputs) ⇒ string
45 | Generates constructor args bytecode based on input data.
46 |
47 | **Kind**: global function
48 | **Returns**: string - bytecode - Constructor args bytecode
49 |
50 | | Param | Type | Description |
51 | | --- | --- | --- |
52 | | inputs | Array.<Object> | Array of objects with name, and type fields |
53 | | inputs[].name | string | Name of argument |
54 | | inputs[].type | string | Type of argument |
55 |
56 |
57 |
58 |
59 | ### decodeFunctionArgs(contractABI, bytecode) ⇒ Object
60 | Decodes function args.
61 |
62 | **Kind**: global function
63 | **Returns**: Object - decodedArgs - Object representing decoded args with name, type, and data fields
64 |
65 | | Param | Type | Description |
66 | | --- | --- | --- |
67 | | contractABI | Object | ABI of contract whose args to decode |
68 | | bytecode | string | function args bytecode, methohID included |
69 |
70 |
71 | ### Supported Types
72 | - [x] bool
73 | - [x] uint
74 | - [x] int
75 | - [ ] fixed
76 | - [x] address
77 | - [x] bytes1, bytes2, bytes3, ..., bytes32
78 | - [x] byte
79 | - [x] string
80 | - [x] arrays
81 | - [ ] multi-dimensional arrays
82 | - [ ] mapping
83 | - [ ] struct
84 |
85 | ## Example
86 |
87 | const { decodeConstructorArgs } = require('canoe-solidity');
88 | let abiExample = {
89 | 'abi': [
90 | {
91 | 'anonymous': false,
92 | 'inputs': [
93 | {
94 | 'name': 'addresses',
95 | 'type': 'address[]',
96 | },
97 | {
98 | 'name': 'quantities',
99 | 'type': 'uint256[]',
100 | },
101 | {
102 | 'name': '_creationUnit',
103 | 'type': 'uint256',
104 | },
105 | {
106 | 'name': '_name',
107 | 'type': 'string',
108 | },
109 | {
110 | 'name': '_symbol',
111 | 'type': 'string',
112 | }
113 | ],
114 | 'payable': false,
115 | 'stateMutability': 'nonpayable',
116 | 'type': 'constructor'
117 | }
118 | ]
119 | };
120 | let bytecodeExample = '00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000008ac7230489e80000000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000ffffffffffffffffffffffffffffffffffffffff000000000000000000000000f1e48f13768bd8114a530070b43257a63f24bb1200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000012457468657265756d31302051322d32303138000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034531300000000000000000000000000000000000000000000000000000000000';
121 | decodeConstructorArgs(abiExample.abi, bytecodeExample);
122 |
123 | Output:
124 |
125 | [
126 | {
127 | "name": "addresses",
128 | "type": "address[]",
129 | "data": [
130 | "ffffffffffffffffffffffffffffffffffffffff",
131 | "f1e48f13768bd8114a530070b43257a63f24bb12"
132 | ]
133 | },
134 | {
135 | "name": "quantities",
136 | "type": "uint256[]",
137 | "data": [
138 | "5",
139 | "10"
140 | ]
141 | },
142 | {
143 | "name": "_creationUnit",
144 | "type": "uint256",
145 | "data": "10000000000000000000"
146 | },
147 | {
148 | "name": "_name",
149 | "type": "string",
150 | "data": "Ethereum10 Q2-2018"
151 | },
152 | {
153 | "name": "_symbol",
154 | "type": "string",
155 | "data": "E10"
156 | }
157 | ]
158 |
--------------------------------------------------------------------------------
/data/abis/MintableNFT.json:
--------------------------------------------------------------------------------
1 | [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"token","type":"address"}],"name":"reclaimToken","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"tokenTypeQuantity","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"bitsMask","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"getOwnedTokensIds","outputs":[{"name":"tokensIds","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"maxMask","outputs":[{"name":"","type":"uint248"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"contractAddr","type":"address"}],"name":"reclaimContract","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_beneficiary","type":"address"},{"name":"_tokenType","type":"uint256"}],"name":"mint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"exists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenTypes","type":"uint256[]"},{"name":"_quantities","type":"uint248[]"}],"name":"setTokensQuantity","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"reclaimEther","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"},{"name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"from_","type":"address"},{"name":"value_","type":"uint256"},{"name":"data_","type":"bytes"}],"name":"tokenFallback","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"tokenTypeAvailableQuantity","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_minter","type":"address"},{"name":"_isAuthorized","type":"bool"}],"name":"setAuthorizedMinter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"_authorizedMinters","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isMintableNFT","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_name","type":"string"},{"name":"_symbol","type":"string"},{"name":"_bytesMask","type":"uint8"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":false,"stateMutability":"nonpayable","type":"fallback"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_approved","type":"address"},{"indexed":false,"name":"_tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_operator","type":"address"},{"indexed":false,"name":"_approved","type":"bool"}],"name":"ApprovalForAll","type":"event"}]
2 |
--------------------------------------------------------------------------------
/test/index.test.js:
--------------------------------------------------------------------------------
1 | const chai = require('chai');
2 | const assert = chai.assert;
3 | const { encodeConstructorArgs, decodeConstructorArgs, decodeFunctionArgs } = require('../index.js');
4 |
5 |
6 | describe('single values', function() {
7 |
8 | it('should correctly decode bool', function() {
9 | const contractABI = {
10 | 'abi': [
11 | {
12 | 'inputs': [
13 | {
14 | 'name': 'bool',
15 | 'type': 'bool',
16 | //'data': true
17 | },
18 | ],
19 | 'payable': false,
20 | 'stateMutability': 'nonpayable',
21 | 'type': 'constructor'
22 | },
23 | ]
24 | };
25 | const bytecode = '0000000000000000000000000000000000000000000000000000000000000001';
26 | const result = decodeConstructorArgs(contractABI.abi, bytecode);
27 | const expected = [
28 | {
29 | 'name': 'bool',
30 | 'type': 'bool',
31 | 'data': 'true'
32 | }
33 | ];
34 | assert.deepEqual(result, expected, 'output should match expected');
35 | });
36 |
37 | it('should correctly decode uint256', function() {
38 | const contractABI = {
39 | 'abi': [
40 | {
41 | 'inputs': [
42 | {
43 | 'name': 'uint256',
44 | 'type': 'uint256',
45 | //'data': 31419526535
46 | },
47 | ],
48 | 'payable': false,
49 | 'stateMutability': 'nonpayable',
50 | 'type': 'constructor'
51 | },
52 | ]
53 | };
54 | const bytecode = '0000000000000000000000000000000000000000000000000000000750bfed87';
55 | const result = decodeConstructorArgs(contractABI.abi, bytecode);
56 | const expected = [
57 | {
58 | 'name': 'uint256',
59 | 'type': 'uint256',
60 | 'data': '31419526535'
61 | }
62 | ];
63 | assert.deepEqual(result, expected, 'output should match expected');
64 | });
65 |
66 | it('should correctly decode int256', function() {
67 | const contractABI = {
68 | 'abi': [
69 | {
70 | 'inputs': [
71 | {
72 | 'name': 'int256',
73 | 'type': 'int256',
74 | //'data': -14
75 | },
76 | ],
77 | 'payable': false,
78 | 'stateMutability': 'nonpayable',
79 | 'type': 'constructor'
80 | },
81 | ]
82 | };
83 | const bytecode = 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2';
84 | const result = decodeConstructorArgs(contractABI.abi, bytecode);
85 | const expected = [
86 | {
87 | 'name': 'int256',
88 | 'type': 'int256',
89 | 'data': '-14'
90 | }
91 | ];
92 | assert.deepEqual(result, expected, 'output should match expected');
93 | });
94 |
95 | it('should correctly decode address', function() {
96 | const contractABI = {
97 | 'abi': [
98 | {
99 | 'inputs': [
100 | {
101 | 'name': 'address',
102 | 'type': 'address',
103 | //'data': '0xF1E48f13768bD8114A530070b43257a63f24bb12'
104 | },
105 | ],
106 | 'payable': false,
107 | 'stateMutability': 'nonpayable',
108 | 'type': 'constructor'
109 | },
110 | ]
111 | };
112 | const bytecode = '000000000000000000000000f1e48f13768bd8114a530070b43257a63f24bb12';
113 | const result = decodeConstructorArgs(contractABI.abi, bytecode);
114 | const expected = [
115 | {
116 | 'name': 'address',
117 | 'type': 'address',
118 | 'data': 'f1e48f13768bd8114a530070b43257a63f24bb12'
119 | }
120 | ];
121 | assert.deepEqual(result, expected, 'output should match expected');
122 | });
123 |
124 | it('should correctly decode bytes16', function() {
125 | const contractABI = {
126 | 'abi': [
127 | {
128 | 'inputs': [
129 | {
130 | 'name': 'bytes16',
131 | 'type': 'bytes16',
132 | //'data': '0xaaaabbbbccccdddd'
133 | },
134 | ],
135 | 'payable': false,
136 | 'stateMutability': 'nonpayable',
137 | 'type': 'constructor'
138 | },
139 | ]
140 | };
141 | const bytecode = 'aaaabbbbccccdddd000000000000000000000000000000000000000000000000';
142 | const result = decodeConstructorArgs(contractABI.abi, bytecode);
143 | const expected = [
144 | {
145 | 'name': 'bytes16',
146 | 'type': 'bytes16',
147 | 'data': 'aaaabbbbccccdddd0000000000000000'
148 | }
149 | ];
150 | assert.deepEqual(result, expected, 'output should match expected');
151 | });
152 |
153 |
154 | it('should correctly decode string', function() {
155 | const contractABI = {
156 | 'abi': [
157 | {
158 | 'inputs': [
159 | {
160 | 'name': 'string',
161 | 'type': 'string',
162 | //'data': 'Bskt is the best!'
163 | },
164 | ],
165 | 'payable': false,
166 | 'stateMutability': 'nonpayable',
167 | 'type': 'constructor'
168 | },
169 | ]
170 | };
171 | const bytecode = '0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001142736b7420697320746865206265737421000000000000000000000000000000';
172 | const result = decodeConstructorArgs(contractABI.abi, bytecode);
173 | const expected = [
174 | {
175 | 'name': 'string',
176 | 'type': 'string',
177 | 'data': 'Bskt is the best!'
178 | }
179 | ];
180 | assert.deepEqual(result, expected, 'output should match expected');
181 | });
182 |
183 |
184 | });
185 |
186 | describe('arrays', function() {
187 |
188 | it('should correctly decode uint256 array', function() {
189 | const contractABI = {
190 | 'abi': [
191 | {
192 | 'inputs': [
193 | {
194 | 'name': 'uint256s',
195 | 'type': 'uint256[]',
196 | //'data': [1, 3, 5, 9, 99]
197 | },
198 | ],
199 | 'payable': false,
200 | 'stateMutability': 'nonpayable',
201 | 'type': 'constructor'
202 | },
203 | ]
204 | };
205 | const bytecode = '0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000063';
206 | const result = decodeConstructorArgs(contractABI.abi, bytecode);
207 | const expected = [
208 | {
209 | 'name': 'uint256s',
210 | 'type': 'uint256[]',
211 | 'data': ['1', '3', '5', '9', '99']
212 | }
213 | ];
214 | assert.deepEqual(result, expected, 'result should match expected');
215 | });
216 |
217 | it('should correctly decode address array', function() {
218 | const contractABI = {
219 | 'abi': [
220 | {
221 | 'inputs': [
222 | {
223 | 'name': 'addresses',
224 | 'type': 'address[]',
225 | //'data': ['0xF1E48f13768bD8114A530070b43257a63f24bb12', '0x0', '0x2']
226 | },
227 | ],
228 | 'payable': false,
229 | 'stateMutability': 'nonpayable',
230 | 'type': 'constructor'
231 | },
232 | ]
233 | };
234 | const bytecode = '00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000f1e48f13768bd8114a530070b43257a63f24bb1200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002';
235 | const result = decodeConstructorArgs(contractABI.abi, bytecode);
236 | const expected = [
237 | {
238 | 'name': 'addresses',
239 | 'type': 'address[]',
240 | 'data': [
241 | 'f1e48f13768bd8114a530070b43257a63f24bb12',
242 | '0000000000000000000000000000000000000000',
243 | '0000000000000000000000000000000000000002']
244 | }
245 | ];
246 | assert.deepEqual(result, expected, 'output should match expected');
247 | });
248 |
249 | it('should correctly decode bytes32 array', function() {
250 | const contractABI = {
251 | 'abi': [
252 | {
253 | 'inputs': [
254 | {
255 | 'name': 'bytes32s',
256 | 'type': 'bytes32[]',
257 | //'data': [
258 | //'0xffffffffffffffffffffffffffffffffffffffff',
259 | //'0xF1E48f13768bD8114A530070b43257a63f24bb12',
260 | //'0xcccccccccccccccccccccccccccccccccccccccc'
261 | //]
262 | },
263 | ],
264 | 'payable': false,
265 | 'stateMutability': 'nonpayable',
266 | 'type': 'constructor'
267 | },
268 | ]
269 | };
270 | const bytecode = '00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003ffffffffffffffffffffffffffffffffffffffff000000000000000000000000f1e48f13768bd8114a530070b43257a63f24bb12000000000000000000000000cccccccccccccccccccccccccccccccccccccccc000000000000000000000000';
271 | const result = decodeConstructorArgs(contractABI.abi, bytecode);
272 | const expected = [
273 | {
274 | 'name': 'bytes32s',
275 | 'type': 'bytes32[]',
276 | 'data': [
277 | 'ffffffffffffffffffffffffffffffffffffffff000000000000000000000000',
278 | 'f1e48f13768bd8114a530070b43257a63f24bb12000000000000000000000000',
279 | 'cccccccccccccccccccccccccccccccccccccccc000000000000000000000000'
280 | ]
281 | },
282 | ];
283 | assert.deepEqual(result, expected, 'result should match expected');
284 | });
285 |
286 | it('should correctly decode bytes4 array', function() {
287 | const contractABI = {
288 | 'abi': [
289 | {
290 | 'inputs': [
291 | {
292 | 'name': 'bytes4s',
293 | 'type': 'bytes4[]',
294 | //'data': [
295 | //'0xff',
296 | //'0xF1E48f13'
297 | //]
298 | },
299 | ],
300 | 'payable': false,
301 | 'stateMutability': 'nonpayable',
302 | 'type': 'constructor'
303 | },
304 | ]
305 | };
306 | const bytecode = '00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002ff00000000000000000000000000000000000000000000000000000000000000f1e48f1300000000000000000000000000000000000000000000000000000000';
307 | const result = decodeConstructorArgs(contractABI.abi, bytecode);
308 | const expected = [
309 | {
310 | 'name': 'bytes4s',
311 | 'type': 'bytes4[]',
312 | 'data': [
313 | 'ff000000',
314 | 'f1e48f13'
315 | ]
316 | },
317 | ];
318 | assert.deepEqual(result, expected, 'result should match expected');
319 | });
320 |
321 | it('should correctly decode bytes array', function() {
322 | const contractABI = {
323 | 'abi': [
324 | {
325 | 'inputs': [
326 | {
327 | 'name': 'bytes',
328 | 'type': 'bytes',
329 | //'data': [
330 | //'0xaa',
331 | //'0xbb',
332 | //'0xcc',
333 | //'0xdd'
334 | //]
335 | },
336 | ],
337 | 'payable': false,
338 | 'stateMutability': 'nonpayable',
339 | 'type': 'constructor'
340 | },
341 | ]
342 | };
343 | const bytecode = '00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004aabbccdd00000000000000000000000000000000000000000000000000000000';
344 | const result = decodeConstructorArgs(contractABI.abi, bytecode);
345 | const expected = [
346 | {
347 | 'name': 'bytes',
348 | 'type': 'bytes',
349 | 'data': 'aabbccdd'
350 | },
351 | ];
352 | assert.deepEqual(result, expected, 'result should match expected');
353 | });
354 |
355 |
356 | });
357 |
358 | describe('real world contracts', function() {
359 |
360 | it('should correctly decode MintableNFT', function() {
361 | const abi = require('../data/abis/MintableNFT.json');
362 | const bytecode = require('../data/bytecodes/MintableNFT.json')['constructor-bytecode'];
363 | const expected = [
364 | { name: '_name', type: 'string', data: 'ExperimentalNFT' },
365 | { name: '_symbol', type: 'string', data: 'e11nft' },
366 | { name: '_bytesMask', type: 'uint8', data: '12' }
367 | ];
368 | const result = decodeConstructorArgs(abi, bytecode);
369 | assert.deepEqual(result, expected, 'result should match expected')
370 | });
371 |
372 | it('should correctly decode EnclavesDEXProxy', function() {
373 | const abi = require('../data/abis/EnclavesDEXProxy.json');
374 | const bytecode = require('../data/bytecodes/EnclavesDEXProxy.json')['constructor-bytecode'];
375 | const expected = [
376 | {
377 | 'name': '_storageAddress',
378 | 'type': 'address',
379 | 'data': '129caf12c70fe9633fe24b15497adafc913c842c'
380 | },
381 | {
382 | 'name': '_implementation',
383 | 'type': 'address',
384 | 'data': 'ed06d46ffb309128c4458a270c99c824dc127f5d'
385 | },
386 | {
387 | 'name': '_admin',
388 | 'type': 'address',
389 | 'data': 'e03793e63776cf69fe42414ed03bb924d4d9157e'
390 | },
391 | {
392 | 'name': '_feeAccount',
393 | 'type': 'address',
394 | 'data': 'e03793e63776cf69fe42414ed03bb924d4d9157e'
395 | },
396 | {
397 | 'name': '_feeTake',
398 | 'type': 'uint256',
399 | 'data': '2000000000000000'
400 | },
401 | {
402 | 'name': '_feeAmountThreshold',
403 | 'type': 'uint256',
404 | 'data': '100000000000000000'
405 | },
406 | {
407 | 'name': '_etherDelta',
408 | 'type': 'address',
409 | 'data': '8d12a197cb00d4747a1fe03395095ce2a5cc6819'
410 | },
411 | {
412 | 'name': '_tradeABIHash',
413 | 'type': 'bytes32',
414 | 'data': '57d54158692b43b05f55462695c3dc04b0217afddfda3f27a07ec31ee46b9c20'
415 | },
416 | {
417 | 'name': '_withdrawABIHash',
418 | 'type': 'bytes32',
419 | 'data': '369521fb20e3cff93d515dad43dc9f9f23dfdbb8d0ca564c480634d401bf9aa1'
420 | }
421 | ];
422 | const result = decodeConstructorArgs(abi, bytecode);
423 | assert.deepEqual(result, expected, 'result should match expected')
424 | });
425 |
426 | });
427 |
428 | describe('decode function', function() {
429 |
430 | it('should correctly decode erc20 transfer', function() {
431 | const contractABI = {
432 | 'abi': [
433 | {
434 | "constant": true,
435 | "inputs": [
436 |
437 | ],
438 | "name": "name",
439 | "outputs": [
440 | {
441 | "name": "",
442 | "type": "string"
443 | }
444 | ],
445 | "payable": false,
446 | "stateMutability": "view",
447 | "type": "function"
448 | },
449 | {
450 | "constant": false,
451 | "inputs": [
452 | {
453 | "name": "spender",
454 | "type": "address"
455 | },
456 | {
457 | "name": "value",
458 | "type": "uint256"
459 | }
460 | ],
461 | "name": "approve",
462 | "outputs": [
463 | {
464 | "name": "",
465 | "type": "bool"
466 | }
467 | ],
468 | "payable": false,
469 | "stateMutability": "nonpayable",
470 | "type": "function"
471 | },
472 | {
473 | "constant": true,
474 | "inputs": [
475 |
476 | ],
477 | "name": "totalSupply",
478 | "outputs": [
479 | {
480 | "name": "",
481 | "type": "uint256"
482 | }
483 | ],
484 | "payable": false,
485 | "stateMutability": "view",
486 | "type": "function"
487 | },
488 | {
489 | "constant": false,
490 | "inputs": [
491 | {
492 | "name": "from",
493 | "type": "address"
494 | },
495 | {
496 | "name": "to",
497 | "type": "address"
498 | },
499 | {
500 | "name": "value",
501 | "type": "uint256"
502 | }
503 | ],
504 | "name": "transferFrom",
505 | "outputs": [
506 | {
507 | "name": "",
508 | "type": "bool"
509 | }
510 | ],
511 | "payable": false,
512 | "stateMutability": "nonpayable",
513 | "type": "function"
514 | },
515 | {
516 | "constant": true,
517 | "inputs": [
518 |
519 | ],
520 | "name": "decimals",
521 | "outputs": [
522 | {
523 | "name": "",
524 | "type": "uint256"
525 | }
526 | ],
527 | "payable": false,
528 | "stateMutability": "view",
529 | "type": "function"
530 | },
531 | {
532 | "constant": false,
533 | "inputs": [
534 | {
535 | "name": "spender",
536 | "type": "address"
537 | },
538 | {
539 | "name": "addedValue",
540 | "type": "uint256"
541 | }
542 | ],
543 | "name": "increaseAllowance",
544 | "outputs": [
545 | {
546 | "name": "success",
547 | "type": "bool"
548 | }
549 | ],
550 | "payable": false,
551 | "stateMutability": "nonpayable",
552 | "type": "function"
553 | },
554 | {
555 | "constant": false,
556 | "inputs": [
557 |
558 | ],
559 | "name": "unpause",
560 | "outputs": [
561 |
562 | ],
563 | "payable": false,
564 | "stateMutability": "nonpayable",
565 | "type": "function"
566 | },
567 | {
568 | "constant": false,
569 | "inputs": [
570 | {
571 | "name": "value",
572 | "type": "uint256"
573 | }
574 | ],
575 | "name": "burn",
576 | "outputs": [
577 |
578 | ],
579 | "payable": false,
580 | "stateMutability": "nonpayable",
581 | "type": "function"
582 | },
583 | {
584 | "constant": true,
585 | "inputs": [
586 |
587 | ],
588 | "name": "paused",
589 | "outputs": [
590 | {
591 | "name": "",
592 | "type": "bool"
593 | }
594 | ],
595 | "payable": false,
596 | "stateMutability": "view",
597 | "type": "function"
598 | },
599 | {
600 | "constant": true,
601 | "inputs": [
602 | {
603 | "name": "owner",
604 | "type": "address"
605 | }
606 | ],
607 | "name": "balanceOf",
608 | "outputs": [
609 | {
610 | "name": "",
611 | "type": "uint256"
612 | }
613 | ],
614 | "payable": false,
615 | "stateMutability": "view",
616 | "type": "function"
617 | },
618 | {
619 | "constant": false,
620 | "inputs": [
621 |
622 | ],
623 | "name": "pause",
624 | "outputs": [
625 |
626 | ],
627 | "payable": false,
628 | "stateMutability": "nonpayable",
629 | "type": "function"
630 | },
631 | {
632 | "constant": true,
633 | "inputs": [
634 |
635 | ],
636 | "name": "owner",
637 | "outputs": [
638 | {
639 | "name": "",
640 | "type": "address"
641 | }
642 | ],
643 | "payable": false,
644 | "stateMutability": "view",
645 | "type": "function"
646 | },
647 | {
648 | "constant": true,
649 | "inputs": [
650 |
651 | ],
652 | "name": "isOwner",
653 | "outputs": [
654 | {
655 | "name": "",
656 | "type": "bool"
657 | }
658 | ],
659 | "payable": false,
660 | "stateMutability": "view",
661 | "type": "function"
662 | },
663 | {
664 | "constant": true,
665 | "inputs": [
666 |
667 | ],
668 | "name": "symbol",
669 | "outputs": [
670 | {
671 | "name": "",
672 | "type": "string"
673 | }
674 | ],
675 | "payable": false,
676 | "stateMutability": "view",
677 | "type": "function"
678 | },
679 | {
680 | "constant": false,
681 | "inputs": [
682 | {
683 | "name": "spender",
684 | "type": "address"
685 | },
686 | {
687 | "name": "subtractedValue",
688 | "type": "uint256"
689 | }
690 | ],
691 | "name": "decreaseAllowance",
692 | "outputs": [
693 | {
694 | "name": "success",
695 | "type": "bool"
696 | }
697 | ],
698 | "payable": false,
699 | "stateMutability": "nonpayable",
700 | "type": "function"
701 | },
702 | {
703 | "constant": false,
704 | "inputs": [
705 | {
706 | "name": "to",
707 | "type": "address"
708 | },
709 | {
710 | "name": "value",
711 | "type": "uint256"
712 | }
713 | ],
714 | "name": "transfer",
715 | "outputs": [
716 | {
717 | "name": "",
718 | "type": "bool"
719 | }
720 | ],
721 | "payable": false,
722 | "stateMutability": "nonpayable",
723 | "type": "function"
724 | },
725 | {
726 | "constant": true,
727 | "inputs": [
728 | {
729 | "name": "owner",
730 | "type": "address"
731 | },
732 | {
733 | "name": "spender",
734 | "type": "address"
735 | }
736 | ],
737 | "name": "allowance",
738 | "outputs": [
739 | {
740 | "name": "",
741 | "type": "uint256"
742 | }
743 | ],
744 | "payable": false,
745 | "stateMutability": "view",
746 | "type": "function"
747 | },
748 | {
749 | "constant": false,
750 | "inputs": [
751 | {
752 | "name": "newOwner",
753 | "type": "address"
754 | }
755 | ],
756 | "name": "transferOwnership",
757 | "outputs": [
758 |
759 | ],
760 | "payable": false,
761 | "stateMutability": "nonpayable",
762 | "type": "function"
763 | },
764 | {
765 | "inputs": [
766 | {
767 | "name": "initialSupply",
768 | "type": "uint256"
769 | },
770 | {
771 | "name": "tokenName",
772 | "type": "string"
773 | },
774 | {
775 | "name": "decimalUnits",
776 | "type": "uint256"
777 | },
778 | {
779 | "name": "tokenSymbol",
780 | "type": "string"
781 | }
782 | ],
783 | "payable": false,
784 | "stateMutability": "nonpayable",
785 | "type": "constructor"
786 | },
787 | {
788 | "anonymous": false,
789 | "inputs": [
790 |
791 | ],
792 | "name": "Paused",
793 | "type": "event"
794 | },
795 | {
796 | "anonymous": false,
797 | "inputs": [
798 |
799 | ],
800 | "name": "Unpaused",
801 | "type": "event"
802 | },
803 | {
804 | "anonymous": false,
805 | "inputs": [
806 | {
807 | "indexed": true,
808 | "name": "previousOwner",
809 | "type": "address"
810 | },
811 | {
812 | "indexed": true,
813 | "name": "newOwner",
814 | "type": "address"
815 | }
816 | ],
817 | "name": "OwnershipTransferred",
818 | "type": "event"
819 | },
820 | {
821 | "anonymous": false,
822 | "inputs": [
823 | {
824 | "indexed": true,
825 | "name": "from",
826 | "type": "address"
827 | },
828 | {
829 | "indexed": true,
830 | "name": "to",
831 | "type": "address"
832 | },
833 | {
834 | "indexed": false,
835 | "name": "value",
836 | "type": "uint256"
837 | }
838 | ],
839 | "name": "Transfer",
840 | "type": "event"
841 | },
842 | {
843 | "anonymous": false,
844 | "inputs": [
845 | {
846 | "indexed": true,
847 | "name": "owner",
848 | "type": "address"
849 | },
850 | {
851 | "indexed": true,
852 | "name": "spender",
853 | "type": "address"
854 | },
855 | {
856 | "indexed": false,
857 | "name": "value",
858 | "type": "uint256"
859 | }
860 | ],
861 | "name": "Approval",
862 | "type": "event"
863 | }
864 | ]
865 | };
866 | const argsData = 'a9059cbb000000000000000000000000b5dc69f37dc69f559b6931defefca2e67ab7645500000000000000000000000000000000000000000000152d02c7e14af6800000';
867 | const result = decodeFunctionArgs(contractABI.abi, argsData);
868 | const expected = [
869 | {
870 | 'name': 'to',
871 | 'type': 'address',
872 | 'data': 'b5dc69f37dc69f559b6931defefca2e67ab76455'
873 | },
874 | {
875 | 'name': 'value',
876 | 'type': 'uint256',
877 | 'data': '100000000000000000000000'
878 | }
879 | ];
880 | assert.deepEqual(result, expected, 'result should match expected');
881 | });
882 | })
--------------------------------------------------------------------------------