GithubHelp home page GithubHelp logo

equilibrium-exchange-wrappers's Introduction

@equilab/exchange

Package of wrappers to work with EOS contract equiexchange.

Usage

Install the module using NPM:

$ npm install @equilab/exchange
const { ExchangeContract, Connection } = require("@equilab/exchange")

const nodeAddress = "http://node-address.example.com:80"
const connection = new Connection(nodeAddress, ["private-key-1", "private-key-2"])
const exchange = new ExchangeContract(connection)

Methods

  • exchange - exchange a given amount of currency.
  • getPair - returns currency pair object for given currencies.
  • getAllPairs - returns an array of all currency pairs objects.
  • getToken - returns token object for specified currency.
  • getAllTokens - returns an array of all currency tokens.
  • getSettings - return Exchange contract settings.
  • getExchangeRate - return exchange rate between two currencies.

Examples

Connecting to blockchain

This code block is required for any other example to work.

const { ExchangeContract, Connection } = require("@equilab/exchange")

// Change node address here. This one will connect you to Jungle testnet node
const nodeAddress = "http://jungle2.cryptolions.io:80"

// Change or add private keys used to sign transactions here. This one is from Jungle
// testnet account "exampleaccnt"
const privateKeys = ["5J5ks3bbRNtQFm7cZwJ6mbiWQoxoMtUDzLG7BAtcmagi5h9Mp5N"]
const accountName = "exampleaccnt"

const connection = new Connection(nodeAddress, privateKeys)
const exchange = new ExchangeContract(connection)

// This code logs current block number and lets us know that connection
// has been  established.
const currentBlockNumber = (await exchange.connection.rpc.get_info()).head_block_num
console.log(`Connected to blockchain, current block number is: ${currentBlockNumber}`)

Exchanging EOS

// Exchanging 10 EOS to EOSDT
await exchange.exchange(accountName, "EOS", "EOSDT", 10)

Exchange rates

// Getting current conversion rate from EOS to EOSDT
let rate = await exchange.getExchangeRate("EOS", "EOSDT")

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.