Flooz.trade SDK
Flooz.trade SDK allows to easily integrate Multichain token swaps on Ethereum Mainnet, Binance Smart Chain & Polygon.
Under the hood it's leveraging 0x API to aggregate & provide the best price across over 70 DEXes.
More information can also be found here.
Getting started
-
Install the
@flooz/trade-sdk
package:yarn add @flooz/sdk
-
Import the SDK:
import { Flooz } from '@flooz/trade-sdk';
Examples
This walks through, how to setup the SDK & execute swaps & trades. A working example can also be found in the ./examples folder.
Setup currencies
import { Token } from './src/common/token';
import { Ether } from './src/common/ether';
// Initialize native Currencies on each Chain
const ETH = Ether.onChain(1);
const BNB = Ether.onChain(56);
const MATIC = Ether.onChain(137);
// Initialize BSC Token
const BUSD = new Token(56, '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56', 18, 'BUSD', 'BUSD Token');
const SYA = new Token(56, '0x83A86adf1a7c56e77d36d585B808052e0a2aAD0e', 9, 'SYA', 'Save Your Assets', 10);
// Initialize ETH MAINNET Token
const DAI = new Token(1, '0x6b175474e89094c44da98b954eedeac495271d0f', 18, 'DAI', 'Dai Stablecoin');
// Initialize POLYGON Token
const USDC = new Token(137, '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', 6, 'USDC', 'USD Coin');
Get a quote
Returns a quote with the best price found.
const quote = await new Flooz().getQuote({
userAddress: '0xb44ac514588BE99870220d12120815bc3D349507',
sellCurrency: BUSD,
buyCurrency: SYA,
sellAmount: BigNumber.from('1000')
buyAmount: BigNumber.from('0')
slippage: 0,
)
Get a swap Transaction
Returns a quote with the best price found & a transaction to execute the Transaction for the user on the Blockchain.
const swapTransaction = await new Flooz().getSwapTransaction({
userAddress: '0xb44ac514588BE99870220d12120815bc3D349507',
sellCurrency: BUSD,
buyCurrency: SYA,
sellAmount: BigNumber.from('1000')
buyAmount: BigNumber.from('0')
slippage: 0,
})