lando-canoe-solidity

0.1.0 • Public • Published

🛶 Canoe Solidity

From https://github.com/cryptofinlabs/canoe-solidity, only for npm publish.

For that Canoe Solidity not export decodeFunctionArgs interface.

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 lando-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

  • [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"
  }
]

Readme

Keywords

none

Package Sidebar

Install

npm i lando-canoe-solidity

Weekly Downloads

2

Version

0.1.0

License

ISC

Unpacked Size

49 kB

Total Files

10

Last publish

Collaborators

  • landoyjx