npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

abi2lib

v0.2.13

Published

Ingests a smart contract's ABI and autogenerates boilerplate code for making web3 calls.

Downloads

29

Readme

abi2lib

An easy way to autogenerate boilerplate code for calling web3.js so your app can communicate with Ethereum.

Installation

Install globally via npm, yarn, or your preferred Javascript package manager:

npm install -g abi2lib

// OR

yarn global add abi2lib

If you are on Windows, you might need to refresh your path by restarting the terminal.

You can also install abi2lib in your own project

npm install --save abi2lib

// OR 

yarn global add abi2lib

Usage

CLI

Use in your terminal of choice by running:

abi2lib <contract_path> [options]

The options let you specify config values directly in the command, or specify a path to a config file. If you do not specify an output directory via an option, then it will be created in the working one. Run abi2lib --help to learn more.

Module

Use in your own nodejs scripts:

const abi2lib = require('abi2lib');

abi2lib.generate(contract_path, output_folder, config_options);

Output

Either of these methods will generate a directory named <ContractName>ContractLib which contains all of your autogenerated code. You can then use that code to communicate with your smart contract via:

const BaseController = require('<ContractName>ContractLib/<ContractName>Controller.js');

const ContractController = new BaseController();

// Async method, returns Promise; configures library with 
// network ID of currently active network.
await ContractController.detectNetwork();

// Perform transaction using config values & required inputs
ContractController.post_<fxnA>(fromAddr, [value if allowed], ...contractInputs);

// Query output of contract using required inputs, does not perform transaction
ContractController.get_<fxnB>(fromAddr, ...contractInputs);

Config

The optional config object includes constants for configuring web3 calls.

{
  "eth": {                                      
    "provider": "http://localhost:8545",       
    "default_gas": 0,                      
    "default_gasPrice": 40            
  }
}

Connector Methods

The Controller class will have methods corresponding to each of the function descriptions listed in the ABI. If the function can be called with inputs, then there will be a method shaped like:

post_<fxnName>(from, [value if fxn is payable], [fxnParams...]){
	// Properly configured call to contract's `send` function, triggers transaction
}

If the function also has outputs, then there will be a method shaped like:

get_<fxnName>(from, [inputParams...]){
	// Properly configured call to contract's `call` function, triggers no transaction
}

Output Structure

Outputs a directory named <ContractName>ContractLib which contains:

  1. GenericEthConnector.js : Generically converts ethereum read/write calls into web3 calls.
  2. <ContractName>Controller.js : Contains all generated methods corresponding to the contract.
  3. contract.json : A copy of your chosen smart contract ABI JSON
  4. config.json : A copy of your chosen config JSON

Licensing

abi2lib is developed & maintained by Eximchain, released for public use under the Apache-2.0 License.

Output from abi2lib uses the same license.