Coder Social home page Coder Social logo

bancor-sdk's Introduction

Bancor SDK v0.1 (beta)

Javascript API that provides utilities and access to the Bancor Network mainnet contracts across the different blockchains using a unified & simplified interface.

Initialization

const bancor = require('bancor-sdk');

await bancor.init({
    // optional, mandatory when interacting with the ethereum mainnet
    ethereumNodeEndpoint: '<ethereum node endpoint>',
    // optional, mandatory when interacting with the EOS mainnet
    eosNodeEndpoint: '<eos node endpoint>',
    // optional, can be used along with an ethereum ropsten endpoint to interact with the ropsten deployment of the contracts
    // the default value for the argument is the mainnet contract address 
    ethereumContractRegistryAddress: '<ethereum contract registry address>',
});

Usage

Price discovery - used to get the conversion rate between any two tokens in the Bancor Network. Note that the source token and the target token can reside on two different blockchains. In addition, amount input format is a decimal big number (as opposed to wei) since the function is blockchain agnostic.

// get the rate between DAI and ENJ
const sourceToken = {
    blockchainType: 'ethereum',
    blockchainId: '0x6B175474E89094C44Da98b954EedeAC495271d0F'
};
const targetToken = {
    blockchainType: 'ethereum',
    blockchainId: '0xF629cBd94d3791C9250152BD8dfBDF380E2a3B9c'
};
const rate = await bancor.getRate(sourceToken, targetToken, "1.0");

// output:
12.946537808892427162

Conversion path generation - used to generate a path that can then be used for on-chain conversions. Note that the source token and the target token can reside on two different blockchains.

// generate the path between ETH and BNT
const sourceToken = {
    blockchainType: 'ethereum',
    blockchainId: '0xc0829421C1d260BD3cB3E0F06cfE2D52db2cE315'
};
const targetToken = {
    blockchainType: 'ethereum',
    blockchainId: '0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C'
};
const path = await bancor.generatePath(sourceToken, targetToken);

// output:
{
	"paths": [{
		"type": "ethereum",
		"path": [
            "0xc0829421c1d260bd3cb3e0f06cfe2d52db2ce315",
            "0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C",
            "0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c"
        ]
	}]
}

Deinitialization

await bancor.deinit();

Features

  • Price discovery
  • Conversion path generation
  • Full cross-chain support

Collaborators

bancor-sdk's People

Contributors

barakman avatar deacix avatar yudilevi avatar yudilevi2 avatar

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.