# @mobinpo/canoe-solidity

> Lightweight Javascript library for decoding constructor arguments.

Latest version **0.1.0** (published 2020-09-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install @mobinpo/canoe-solidity
pnpm add @mobinpo/canoe-solidity
yarn add @mobinpo/canoe-solidity
bun add @mobinpo/canoe-solidity
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2020-09-06 |
| First published | 2020-09-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 47.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | dmdque |
| Maintainers | mobinpo |

## Links

- npm: https://www.npmjs.com/package/@mobinpo/canoe-solidity
- Homepage: https://github.com/mobinpo/canoe-solidity
- npm.io page: https://npm.io/package/@mobinpo/canoe-solidity

## Dependencies (3)

- [underscore](https://npm.io/package/underscore.md) ^1.9.1
- [ethereumjs-abi](https://npm.io/package/ethereumjs-abi.md) ^0.6.5
- [ethereumjs-util](https://npm.io/package/ethereumjs-util.md) ^5.2.0

## Recent versions

- 0.1.0 (latest) — 2020-09-06

## README

# 🛶 Canoe Solidity 
Lightweight Javascript library for decoding constructor arguments.

## Summary
Canoe works by reading a contract's ABI and decoding the constructor bytecode with the argument types provided.

## Install

    npm install canoe-solidity

## Requirements
- ABI schema 2.0

## Documentation
### Functions

<dl>
<dt><a href="#decodeConstructorArgs">decodeConstructorArgs(contractABI, bytecode)</a> ⇒ <code>Object</code></dt>
<dd><p>Decodes constructor args.</p>
</dd>
<dt><a href="#encodeConstructorArgs">encodeConstructorArgs(inputs)</a> ⇒ <code>string</code></dt>
<dd><p>Generates constructor args bytecode based on input data.</p>
</dd>
<dt><a href="#decodeFunctionArgs">decodeFunctionArgs(contractABI, bytecode)</a> ⇒ <code>Object</code></dt>
<dd><p>Decodes function call args.</p>
</dd>
</dl>

<a name="decodeConstructorArgs"></a>

### decodeConstructorArgs(contractABI, bytecode) ⇒ <code>Object</code>
Decodes constructor args.

**Kind**: global function  
**Returns**: <code>Object</code> - decodedArgs - Object representing decoded args with name, type, and data fields  

| Param | Type | Description |
| --- | --- | --- |
| contractABI | <code>Object</code> | ABI of contract whose args to decode |
| bytecode | <code>string</code> | Constructor args bytecode |

<a name="encodeConstructorArgs"></a>

### encodeConstructorArgs(inputs) ⇒ <code>string</code>
Generates constructor args bytecode based on input data.

**Kind**: global function  
**Returns**: <code>string</code> - bytecode - Constructor args bytecode  

| Param | Type | Description |
| --- | --- | --- |
| inputs | <code>Array.&lt;Object&gt;</code> | Array of objects with name, and type fields |
| inputs[].name | <code>string</code> | Name of argument |
| inputs[].type | <code>string</code> | Type of argument |


<a name="decodeFunctionArgs"></a>

### decodeFunctionArgs(contractABI, bytecode) ⇒ <code>Object</code>
Decodes function args.

**Kind**: global function  
**Returns**: <code>Object</code> - decodedArgs - Object representing decoded args with name, type, and data fields  

| Param | Type | Description |
| --- | --- | --- |
| contractABI | <code>Object</code> | ABI of contract whose args to decode |
| bytecode | <code>string</code> | function args bytecode, methohID included |


### Supported Types
- [x] bool
- [x] uint
- [x] int
- [ ] fixed
- [x] address
- [x] bytes1, bytes2, bytes3, ..., bytes32
- [x] byte
- [x] string
- [x] arrays
- [ ] multi-dimensional arrays
- [ ] mapping
- [ ] struct

## Example

    const { decodeConstructorArgs } = require('canoe-solidity');
    let abiExample = {
      'abi': [
        {
          'anonymous': false,
          'inputs': [
            {
              'name': 'addresses',
              'type': 'address[]',
            },
            {
              'name': 'quantities',
              'type': 'uint256[]',
            },
            {
              'name': '_creationUnit',
              'type': 'uint256',
            },
            {
              'name': '_name',
              'type': 'string',
            },
            {
              'name': '_symbol',
              'type': 'string',
            }
          ],
          'payable': false,
          'stateMutability': 'nonpayable',
          'type': 'constructor'
        }
      ]
    };
    let bytecodeExample = '00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000008ac7230489e80000000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000ffffffffffffffffffffffffffffffffffffffff000000000000000000000000f1e48f13768bd8114a530070b43257a63f24bb1200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000012457468657265756d31302051322d32303138000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034531300000000000000000000000000000000000000000000000000000000000';
    decodeConstructorArgs(abiExample.abi, bytecodeExample);

Output:

    [
      {
        "name": "addresses",
        "type": "address[]",
        "data": [
          "ffffffffffffffffffffffffffffffffffffffff",
          "f1e48f13768bd8114a530070b43257a63f24bb12"
        ]
      },
      {
        "name": "quantities",
        "type": "uint256[]",
        "data": [
          "5",
          "10"
        ]
      },
      {
        "name": "_creationUnit",
        "type": "uint256",
        "data": "10000000000000000000"
      },
      {
        "name": "_name",
        "type": "string",
        "data": "Ethereum10 Q2-2018"
      },
      {
        "name": "_symbol",
        "type": "string",
        "data": "E10"
      }
    ]

---
_Source: https://npm.io/package/@mobinpo/canoe-solidity · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
