Xfai Class

The Xfai class is an essential component of the Xfai SDK, which provides a simplified interface to interact with the Web3 blockchain using the Ethers.js library. It serves as a wrapper around various Ethers.js interfaces, offering a more straightforward and intuitive way to perform blockchain operations.

Installation

To use the Xfai SDK and the Xfai class, you need to install it first. You can do this by running the following command:

npm install @xfai-labs/sdk

Importing the Xfai Class

Once the SDK is installed, you can import the Xfai class into your project as follows:

import { Xfai } = '@xfai-labs/sdk';

Creating an Instance

To interact with the Web3 blockchain, you need to create an instance of the Xfai class. You will typically provide the necessary parameters during the instantiation:

const xfai = new Xfai(provider, chain, Permille.from(2));

The provider parameter represents the ethers.js provider you want to connect to. The chain parameter is an object that contains all the contract/token addresses which is provided by the package under the chains object and the third parameter represents the total swap fee used for math calculations.

Class Variables

The Xfai class provides several important variables that you can utilize to interact with the Web3 blockchain. These variables include:

xfai.provider: This variable holds the underlying provider instance used to connect to the Ethereum network. It allows you to access and use the provider directly for any specialized operations not covered by the Xfai class.

Useful tokens

nativeToken: Native token of the chain.

wrappedNativeToken: Wrapped Native token of the chain.

underlyingToken: Xfit token

usdc: USDC Token (Optional used for calculated token values in $ terms)

Contract Addresses

topTokenAddresses: An optional array of string addresses representing the top token addresses.

coreAddress: Contract address of Xfai core

factoryAddress: Contract address of Xfai factory

multicallAddress:Contract address of Multicall V3

inftAddress: Contract address of Xfai INFT

peripheryAddress: Contract address of Xfai Periphery

inftPeripheryAddress: Contract address of Xfai INFT Periphery

poolInitCodeHash: A string representing the pool init code hash used for getting pool address from token address using create2

Initializing the Xfai class

import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { Chains, Xfai } from '@xfai-labs/sdk';


//Chain id
const MAINNET = 1;

const chain = Chains[MAINNET];


// Using the rcp url provided by the chain object, can also be the Web3 provider injected by the browser.
const provider = new StaticJsonRpcProvider(
  {
    url: chain.rpcUrl,
  },
  chain.chainId,
);

const xfai = new Xfai(provider, chain);

Last updated