@kyber.network/reserve-sdk

    0.0.4 • Public • Published

    reserve-sdk.js

    Build Status npm version Document

    Reserve SDK library provides convenient methods to create and operate a KyberNetwork reserve. This package is desinged to work for both client and server side JavaScript application.

    Warning: This is pre-released software, use it at your own risk.

    Installation

    Install the package with:

    npm install --save @kyber.network/reserve-sdk
    

    Documentation

    See the Reserve SDK.s docs.

    Usage

    Creating New Contract

    Deploying a new KyberNetwork will create a number of smart contracts. The returned addresses should be saved to persistent storage to use in operation later.

    Deployment requires a Ethereum node provider and an account.

    Example for server side JavaScript application.

    // requires a Ethereum Remote Node Provider likes: infura.io, etherscan.io...
    const provider = new Web3.providers.HttpProvider('ethereum-node')
    const dpl = new Deployer(provider)
     
    // initialize account from private key
    const account = dpl.web3.eth.accounts.privateKeyToAccount('private-key')
    // initialize account from keystore file
    // const account = dpl.web3.eth.accounts.decrypt(fs.readFileSync(), "your-keystore-passphrase");
     
    dpl.web3.eth.accounts.wallet.add(account)
     
    let addresses;
    (async () => addresses = await dpl.deploy(account))()
     
    console.log(addresses)

    Example for client side Javascript application, using Metamask.

    if (typeof window === "undefined" && typeof window.web3 === "undefined") {
      throw new Error("metamask is not installed");
    }
     
    const dpl = new Deployer(window.web3.currentProvider);
    (async () => {
      const account = (await web3.eth.getAccounts())[0];
      await dpl.deploy(account);
    })();

    Reserve Operations

    The deployed contract addresses will be used for creating a Reserve instance to interact with reserver smart contracts.

    const reserve = new Reserve(provider, addresses);
    (async () => {
      // admin operations
      await reserve.enableTrade();
      await reserve.disableTrade();
      await reserve.setRate(account, rates, 1000);
    })();

    Please consult documentation for detail operation instructions.

    Development

    Run all tests:

    $ npm install
    $ npm test

    Format codes:

    $ npm run format

    Generate documentation:

    $ npm run doc

    Keywords

    none

    Install

    npm i @kyber.network/reserve-sdk

    DownloadsWeekly Downloads

    2

    Version

    0.0.4

    License

    MIT

    Unpacked Size

    5.55 MB

    Total Files

    63

    Last publish

    Collaborators

    • tranvictor
    • kyberliem
    • anyhowclick
    • ayobuenavista
    • ilandoron