Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/synthetixio/js
BETA: Javascript library for interacting with the Synthetix protocol
https://github.com/synthetixio/js
defi ethereum synthetix
Last synced: 11 days ago
JSON representation
BETA: Javascript library for interacting with the Synthetix protocol
- Host: GitHub
- URL: https://github.com/synthetixio/js
- Owner: Synthetixio
- Created: 2020-08-04T02:45:29.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-24T20:12:22.000Z (over 3 years ago)
- Last Synced: 2024-10-30T15:24:31.309Z (19 days ago)
- Topics: defi, ethereum, synthetix
- Language: TypeScript
- Homepage:
- Size: 14.9 MB
- Stars: 9
- Watchers: 16
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Synthetix JS
[![Synthetixio](https://circleci.com/gh/Synthetixio/js.svg?style=svg)](https://github.com/Synthetixio/js)
:warning: 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