All Projects → paraswap → paraswap-sdk

paraswap / paraswap-sdk

Licence: other
ParaSwap allows dApps and traders to get the best DEX liquidity by aggregating multiple markets and offering the best rates

Programming Languages

typescript
32286 projects
API Blueprint
66 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to paraswap-sdk

Mida
The open-source and cross-platform trading framework
Stars: ✭ 263 (+100.76%)
Mutual labels:  exchange, web3
nft-swap-sdk
Ethereum's missing p2p NFT and token swap library for web3 developers. Written in TypeScript. Powered by 0x.
Stars: ✭ 200 (+52.67%)
Mutual labels:  exchange, web3
bitmex-orderbook
The fastest order book implementation for the BitMEX WebSocket API.
Stars: ✭ 73 (-44.27%)
Mutual labels:  exchange
web
ShapeShift Web
Stars: ✭ 40 (-69.47%)
Mutual labels:  web3
0x-tracker-api
NodeJS API built for 0x Tracker which exposes 0x protocol data and metrics for consumption by the 0x Tracker Client application.
Stars: ✭ 19 (-85.5%)
Mutual labels:  web3
trust-api
No description or website provided.
Stars: ✭ 20 (-84.73%)
Mutual labels:  web3
MSE
Malware sample exchange system and API intended for Anti-Virus companies and researchers.
Stars: ✭ 14 (-89.31%)
Mutual labels:  exchange
go-ethutil
Ethereum utility functions for Go.
Stars: ✭ 17 (-87.02%)
Mutual labels:  web3
robinhood.tools
📈🤑💰 Advanced trading tools and resources for Robinhood Web.
Stars: ✭ 27 (-79.39%)
Mutual labels:  exchange
CoinEx.Net
API wrapper for CoinEx
Stars: ✭ 34 (-74.05%)
Mutual labels:  exchange
nft-website
NFT School: Community education platform for developers in the non-fungible token space.
Stars: ✭ 260 (+98.47%)
Mutual labels:  web3
Skill-Tree
Skill tree for the Freshman Track at LearnWeb3DAO
Stars: ✭ 57 (-56.49%)
Mutual labels:  web3
gemini-python
A python client for the Gemini API and Websocket
Stars: ✭ 71 (-45.8%)
Mutual labels:  exchange
currency-converter
💰 Easily convert between 32 currencies
Stars: ✭ 16 (-87.79%)
Mutual labels:  exchange
pancakeswap-lottery
🥞 A Python client for accessing PancakeSwap Lottery smart contract information through Web3.py
Stars: ✭ 30 (-77.1%)
Mutual labels:  web3
itops
基于Python + Django的AD\Exchange管理系统
Stars: ✭ 113 (-13.74%)
Mutual labels:  exchange
crypto-websocket-extensions
🧰 Unified and optimized data structures across cryptocurrency exchanges
Stars: ✭ 31 (-76.34%)
Mutual labels:  exchange
awesome-waves
Curated list of awesome things for development on Waves blockchain.
Stars: ✭ 60 (-54.2%)
Mutual labels:  web3
CVE-2020-0688-Scanner
Quick tool for checking CVE-2020-0688 on multiple hosts with a non-intrusive method.
Stars: ✭ 38 (-70.99%)
Mutual labels:  exchange
mirror-next
A Next.js-powered frontend for your Mirror publication
Stars: ✭ 98 (-25.19%)
Mutual labels:  web3

ParaSwap SDK


API docs are available here :

https://developers.paraswap.network

To use ParaSwap SDK :

Install the lib using npm or yarn

yarn add paraswap
Then on a Javascript file:
const { ParaSwap } = require('paraswap');
const paraSwap = new ParaSwap();

ES6 or TypeScript

import { ParaSwap } from 'paraswap';
const paraSwap = new ParaSwap();
To retrieve the list all available tokens:
const tokens = await paraSwap.getTokens();
To get the rate of a token pair using the API:
const srcToken = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'; // ETH
const destToken = '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359'; // DAI
const srcAmount = '1000000000000000000'; //The source amount multiplied by its decimals: 10 ** 18 here

const priceRoute: OptimalRates = await paraSwap.getRate(
  srcToken,
  destToken,
  srcAmount,
);

Where priceRoute contains the rate and the distribution among exchanges, checkout the OptimalRates type for more details.

To get the rate of a token pair using the Price Feed Contract:

This can be used for trustless integrations, the

const paraswapFeed = new ParaswapFeed(1);
const priceRoute: OptimalRates = await paraswapFeed.getRate(
  srcToken,
  destToken,
  srcAmount,
);

This is a schema that describes the data flow from price query to executing a Swap:

Also available at https://paraswap-achirecture.netlify.com

To get the allowance of an ERC20
const paraSwap = new ParaSwap().setWeb3Provider(web3Provider);

const allowance = await paraSwap.getAllowance(userAddress, tokenAddress);
To approve an ERC20
const paraSwap = new ParaSwap().setWeb3Provider(web3Provider);

const txHash = await paraSwap.approveToken(amount, userAddress, tokenAddress);
To build and sign a transaction
const srcToken = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
const destToken = '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359';
const srcAmount = '1000000000000000000'; //The source amount multiplied by its decimals
const senderAddress = '0xfceA770875E7e6f25E33CEa5188d12Ef234606b4';
const receiver = '0x8B4e846c90a2521F0D2733EaCb56760209EAd51A'; // Useful in case of swap and transfer
const referrer = 'my-company-or-nick-name';

const txParams = await paraSwap.buildTx(
  srcToken,
  destToken,
  srcAmount,
  destAmount,
  priceRoute,
  senderAddress,
  referrer,
  receiver,
);

web3.eth.sendTransaction(
  txParams,
  async (err: Error, transactionHash: string) => {
    if (err) {
      return this.setState({ error: err.toString(), loading: false });
    }
    console.log('transactionHash', transactionHash);
  },
);

To run the example locally:

Created an .env file with these 2 env variables:

PROVIDER_URL=YOUR_PROVIDRER_URL_OR_INFURA_URL
NODE_ENV=production

run

yarn install paraswap

For local developement you can run

yarn dev

For production build:

yarn build

Which will generate a production build on "dist" folder

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].