Skip to content

Lightweight Javascript library for decoding constructor arguments.

License

Notifications You must be signed in to change notification settings

cryptofinlabs/canoe-solidity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛶 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

decodeConstructorArgs(contractABI, bytecode)Object

Decodes constructor args.

encodeConstructorArgs(inputs)string

Generates constructor args bytecode based on input data.

decodeFunctionArgs(contractABI, bytecode)Object

Decodes function call args.

decodeConstructorArgs(contractABI, bytecode) ⇒ Object

Decodes constructor args.

Kind: global function
Returns: Object - decodedArgs - Object representing decoded args with name, type, and data fields

Param Type Description
contractABI Object ABI of contract whose args to decode
bytecode string Constructor args bytecode

encodeConstructorArgs(inputs) ⇒ string

Generates constructor args bytecode based on input data.

Kind: global function
Returns: string - bytecode - Constructor args bytecode

Param Type Description
inputs Array.<Object> Array of objects with name, and type fields
inputs[].name string Name of argument
inputs[].type string Type of argument

decodeFunctionArgs(contractABI, bytecode) ⇒ Object

Decodes function args.

Kind: global function
Returns: Object - decodedArgs - Object representing decoded args with name, type, and data fields

Param Type Description
contractABI Object ABI of contract whose args to decode
bytecode string function args bytecode, methohID included

Supported Types

  • bool
  • uint
  • int
  • fixed
  • address
  • bytes1, bytes2, bytes3, ..., bytes32
  • byte
  • string
  • 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"
  }
]

About

Lightweight Javascript library for decoding constructor arguments.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published