GithubHelp home page GithubHelp logo

isabella232 / js-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from synthetixio/js

0.0 0.0 0.0 15.29 MB

BETA: Javascript library for interacting with the Synthetix protocol

JavaScript 46.78% TypeScript 53.22%

js-1's Introduction

Synthetix JS

Synthetixio

โš ๏ธ This library is still under construction and in BETA, please use with caution.

The official Javascript library for interacting with Synthetix protocol contracts.

This library can be used in 2 different environments:

  1. Common-js module for node environments
  2. UMD module for browser environments

Installation


// For node environments:
const { synthetix } = require('@synthetixio/js');

// For single page applications:
import { synthetix } from '@synthetixio/js';

// For browser environments:
// after running npm build take the index.browser.js file and put it in a script tag
// then you can access synthetix on the window object:
const { synthetix } = window;


const snxjs = synthetix({ network: 'mainnet' });


// Note for typescript applications:
import { synthetix, Network } from '@synthetixio/js';
const snxjs = synthetix({ network: Network.Mainnet });

Usage

// this instance exposes props for the given network: synths, sources, targets, users, etc... as well as helper function toBytes32 - as per synthetix: https://github.com/Synthetixio/synthetix/blob/develop/index.js#L199.
const snxjs = synthetix({ network: 'mainnet' });

// If you want to interact with a contract, simply follow the convention:
// await snxjs[contractName].methodName(arguments)
// many arguments require being formatted toBytes32, which we also provide with the library
// Note can optionally pass in a { blockTag: someBlockNumber } to get data from a specific block instead of {}
E.g:
const unformattedSnxPrice = await snxjs.contracts.ExchangeRates.rateForCurrency(snxjs.toBytes32('SNX'), {});
const unformattedTotalSupply = await snxjs.contracts.SynthsUSD.totalSupply({});

// We also expose ethers utils which provides handy methods for formatting responses to queries.
const { formatEther } = snxjs.utils;

const snxPrice = formatEther(unformattedSnxPrice);
const totalSupply = formatEther(unformattedTotalSupply);

See the examples folder for more usage details

js-1's People

Contributors

evgenyboxer avatar jcmonte avatar jjgonecrypto 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.