Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

abi2api

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abi2api

CLI which ingests smart contract metadata & autogenerates a RESTful nodejs server API

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

abi2api (under construction)

WARNING: This library is a work in progress, not yet fully functional.

Autogenerate a nodejs server with a RESTful OpenAPI so you can communicate with your smart contract of choice via web3. Encapsulate your smart contract so you can leverage the power of blockchain with the convenience of HTTP.

Usage

abi2api is a simple CLI, it has one command which takes two arguments:

abi2api <path_to_config_json> <server_output_path>

The paths should be relative to wherever you are calling the command. abi2api will then convert your smart contract (specified in the config) on a function-by-function basis. Your chosen output path will now contain a file structure like:

  • /api
    • swagger.yaml : YAML version of output OpenAPI spec
  • /controllers
    • contractFxnAScope.js : File connecting /contractFxnA to a dedicated resolver
    • contractFxnAScopeService.js : File which uses our generic ethereum connector to make actual web3 calls to FxnA on our contract
    • ... more files for other contract fxns...
  • /utils
    • writer.js : Swagger util for writing to HTTP requests
  • index.js : Boilerplate code for running a connect server with all Swagger features set up.
  • package.json : Boilerplate values from Swagger
  • README.md : Boilerplate text from Swagger

You can find a more thorough explanation of how abi2api maps smart contracts to an OpenAPI spec over at the abi2oas repository.

Installation

Install the package globally from npm using your favorite package manager:

npm install -g abi2api

// OR

yarn global add abi2api

You will also need to Java (v7 or higher) installed, as this tool depends on Swagger Codegen v2.2.1.

Config

The configuration JSON is the key to using abi2api. It would look something like this (comments just added for explanation):

sample configuration...
{
  "version": "1.0.0",           // Required: API Version for Swagger
  "schemes": ["https"],         // Optional: Allowed Access Schemes for Swagger
  "host": "localhost:8080",     // Optional: Host for Swagger
  "basePath": "/",              // Optional: Base Path for Swagger
  "contract": "<path_to_contract_metadata.json>", // Required: Relative to directory of config file
  "tags": [... Optional: custom Swagger tags, see below ...],
  "api": {... Optional: custom Swagger tag config, see below ...},
  "eth": {                      // Required: Ethereum Configuration
    "provider": "http://localhost:8545", // Required: Web3 provider
    "default_gas": 0,                    // Required: Default Gas for transactions
    "default_gasPrice": 40               // Required: Default Gas Price for transactions
  }
}

If schemes, host, or basePath are left blank, then abi2api will use the values shown above. The tags and api keys let you create additional Swagger tags and connect them to contract methods, you can find more information in the relevant section of abi2oas.

How It Works

abi2api builds a server for your web contract by leveraging the OpenAPI Spec and Swagger Codegen, along with some custom sauce cooked up in-house at Eximchain:

  1. Your smart contract's metadata gets passed through abi2oas, an Eximchain library which generates a JSON according to the OpenAPI spec.
  2. The resulting JSON is passed through swagger-codegen-cli@2.2.1 to generate the nodejs server stub code. These methods do not yet communicate with web3.
  3. Your smart contract's metadata then passes through abi2lib, an Eximchain library which generates boilerplate web3 calls matching the contract spec.
  4. Finally, abi2api does some cleanup work to join the nodejs server stubs from Swagger with the boilerplate web3 calls from abi2lib.

Licensing

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

Output from abi2api uses the same license.

Keywords

FAQs

Package last updated on 10 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc