0.6.1 • Published 1 year ago

@flooz/trade-sdk v0.6.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

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,
})
0.6.1

1 year ago

0.5.0

2 years ago

0.6.0

1 year ago

0.5.1

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.3.20

2 years ago

0.3.23

2 years ago

0.3.22

2 years ago

0.4.0

2 years ago

0.3.18-fix9

2 years ago

0.3.18-fix8

2 years ago

0.3.18-fix7

2 years ago

0.3.18-fix6

2 years ago

0.3.18-fix5

2 years ago

0.3.18-fix4

2 years ago

0.3.18-fix3

2 years ago

0.3.18-fix2

2 years ago

0.3.18-fix

2 years ago

0.3.19

2 years ago

0.3.18

2 years ago

0.3.17

2 years ago