GithubHelp home page GithubHelp logo

michellekwa / canoe-solidity Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cryptofinlabs/canoe-solidity

1.0 2.0 0.0 14 KB

Lightweight Javascript library for decoding constructor arguments.

JavaScript 100.00%

canoe-solidity's Introduction

๐Ÿ›ถ 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-soldity

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.

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

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

canoe-solidity's People

Contributors

dmdque avatar

Stargazers

MK avatar

Watchers

James Cloos avatar MK avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.