0.1.0 • Published 6 years ago

connext-ns v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

JavaScript Style Guide

Introduction

connext-ns is an npm package to provide an interface to the public registry of deployed Ethereum contracts. It provides helper methods to retrieve the address and ABI of the contracts to make dApp development easier.

Installation

npm install connext-ns

Usage

Initialization

const Ns = require('connext-ns')
const ns = new Ns() // constructor variables are optional

Constructor Arguments

const ns = new Ns(localPort = 9545, ethNodeUrl, privateKey)

  • localport - Port for localhost injected Web3 (default is 9545 for truffle develop).
  • ethNodeUrl - URL for connecting to remote ETH node.
  • privateKey - Private key string for unlocking account. PLEASE KEEP THIS SAFE. This package does not send your public key anywhere.

Get Contract Address

Pass in contract name to look up deployed address.

const Ns = require('connext-ns')
const ns = new Ns()
ns
  .lookupAddress('SimpleStorage')
  .then(address => {
    console.log(address)
  })
  .catch(e => console.log(e.toString()))

Output:

'0x8f0483125fcb9aaaefa9209d8e9d7b9c8b9fb90f'

Get Contract ABI

Pass in contract name to get ABI.

const Ns = require('connext-ns')
const ns = new Ns()
ns
  .lookupABI('SimpleStorage')
  .then(abi => {
    console.log(abi)
  })
  .catch(e => console.log(e.toString()))

Output:

[ { constant: false,
       inputs: [Array],
       name: 'set',
       outputs: [],
       payable: false,
       stateMutability: 'nonpayable',
       type: 'function' },
     { constant: true,
       inputs: [],
       name: 'get',
       outputs: [Array],
       payable: false,
       stateMutability: 'view',
       type: 'function' },
     { inputs: [],
       payable: false,
       stateMutability: 'nonpayable',
       type: 'constructor' } ]

Get Everything

Pass in contract name to get both address and ABI.

const Ns = require('connext-ns')
const ns = new Ns()
ns
  .lookup('SimpleStorage')
  .then(result => {
    console.log(result)
  })
  .catch(e => console.log(e.toString()))

Output:

{ address: '0x8f0483125fcb9aaaefa9209d8e9d7b9c8b9fb90f',
  abi:
   [ { constant: false,
       inputs: [Array],
       name: 'set',
       outputs: [],
       payable: false,
       stateMutability: 'nonpayable',
       type: 'function' },
     { constant: true,
       inputs: [],
       name: 'get',
       outputs: [Array],
       payable: false,
       stateMutability: 'view',
       type: 'function' },
     { inputs: [],
       payable: false,
       stateMutability: 'nonpayable',
       type: 'constructor' } ] }