Contracts Interface to Synthetix
The official JavaScript library for interacting with Synthetix protocol contracts.
This library can be used in 2 different environments:
- Common-js module for node environments
- UMD module for browser environments
Instantiating in node.js or the browser
const { synthetix } = require('@synthetixio/contracts-interface');
import { synthetix } from '@synthetixio/contracts-interface';
const { synthetix } = window;
const hznjs = synthetix({ network: 'mainnet' });
import { synthetix, Network } from '@synthetixio/contracts-interface';
const hznjs = synthetix({ network: Network.Mainnet });
Reading state
const hznjs = synthetix({ network: 'mainnet' });
const owner = await hznjs.contracts.Synthetix.owner();
const { toBytes32 } = snx;
const totalIssuedSynths = await hznjs.contracts.Synthetix.totalIssuedSynths(toBytes32('sUSD'));
const { formatEther } = hznjs.utils;
formatEther(await hznjs.contracts.SynthsUSD.totalSupply());
formatEther(await hznjs.contracts.ExchangeRates.rateForCurrency(hznjs.toBytes32('SNX')));
const snxAtBlock12m = await hznjs.contracts.ExchangeRates.rateForCurrency(hznjs.toBytes32('SNX'), {
blockTag: 12e6,
});
Signing transactions
const provider = ethers.providers.getDefaultProvider('kovan');
const signer = new ethers.Wallet(
'0xa0d951c494421559c63089093b020cf2f7aac003c916967dc36e989bc695222e',
provider
);
const hznjs = synthetix({ network: 'mainnet', signer });
const response = await hznjs.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.