0.1.35 • Published 2 years ago

@shibax/contracts-interface v0.1.35

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Contracts Interface to Shibax

The official JavaScript library for interacting with Shibax protocol contracts.

This library can be used in 2 different environments:

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

Instantiating in node.js or the browser

// For node environments:
const { synthetix } = require('@shibax/contracts-interface');

// For single page applications:
import { synthetix } from '@shibax/contracts-interface';

// For browsers you can use a CDN of the minified files
// E.g. <script src="https://cdn.jsdelivr.net/npm/@shibax/contracts-interface/build/index.min.js"></script>
// then you can access synthetix on the window object:
const { synthetix } = window;

// Instantiate the library with or without a provider
const sbxjs = synthetix({ network: 'mainnet' });

// Note: for typescript applications
import { synthetix, Network } from '@shibax/contracts-interface';
const sbxjs = synthetix({ network: Network.Mainnet });

Reading state

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

// If you want to interact with a contract, simply follow the convention:
// await sbxjs[contractName].methodName(arguments)

const owner = await sbxjs.contracts.Shibax.owner();

// many arguments require being formatted toBytes32, which we also provide with the library

const { toBytes32 } = sbx;

const totalIssuedSynths = await sbxjs.contracts.Shibax.totalIssuedSynths(toBytes32('sUSD'));

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

formatEther(await sbxjs.contracts.SynthsUSD.totalSupply());

formatEther(await sbxjs.contracts.ExchangeRates.rateForCurrency(sbxjs.toBytes32('SBX')));

// Note can optionally pass in a { blockTag: someBlockNumber } to get data from a specific block instead of {}
const sbxAtBlock12m = await sbxjs.contracts.ExchangeRates.rateForCurrency(sbxjs.toBytes32('SBX'), {
  blockTag: 12e6,
});

Signing transactions

// any old provider will do
const provider = ethers.providers.getDefaultProvider('kovan');

// create a signer with a provider attached
const signer = new ethers.Wallet(
  // just a dummy kovan wallet with a little keth from the faucet
  '0xa0d951c494421559c63089093b020cf2f7aac003c916967dc36e989bc695222e',
  provider
);

// and then instantiate synthetix with the signer
const sbxjs = synthetix({ network: 'mainnet', signer });

// mint 0.01 sETH via the NativeEtherWrapper
const response = await sbxjs.contracts.NativeEtherWrapper.mint({
  value: parseEther('0.01'),
  gasPrice: parseUnits('5', 'gwei'),
  gasLimit: 500e3,
});
console.log('Submitted', response.hash);
await response.wait();
console.log('Mined', `https://etherscan.io/tx/${response.hash}`);

See the examples folder for more usage details.

0.1.30

3 years ago

0.1.31

3 years ago

0.1.32

3 years ago

0.1.33

2 years ago

0.1.34

2 years ago

0.1.35

2 years ago

0.1.27

3 years ago

0.1.28

3 years ago

0.1.29

3 years ago

0.1.24

3 years ago

0.1.25

3 years ago

0.1.26

3 years ago

0.1.12

3 years ago

0.1.13

3 years ago

0.1.14

3 years ago

0.1.15

3 years ago

0.1.20

3 years ago

0.1.21

3 years ago

0.1.22

3 years ago

0.1.23

3 years ago

0.1.16

3 years ago

0.1.17

3 years ago

0.1.18

3 years ago

0.1.19

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago