ParaSwap SDK – ParaSwap软件开发包区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,ParaSwap SDK – ParaSwap软件开发包区块链毕设代写 是一篇很好的国外资料

ParaSwap SDK

ParaSwap SDK - ParaSwap软件开发包


You can use this SDK in order to swap or pay using ERC-20 tokens.

We’ve built an example dApp that can found here https://github.com/paraswap/demo-dapp

You can also check a live example at: https://paraswap-sdk.netlify.com

ParaSwap SDK - ParaSwap软件开发包


API docs are available here :

https://paraswapv2.docs.apiary.io

To use ParaSwap SDK :

Install the lib using npm or yarn

yarn install 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:

ParaSwap SDK - ParaSwap软件开发包

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


ParaSwap SDK

此处提供API文档:

要使用ParaSwap SDK:

然后在Javascript文件上检索所有可用令牌的列表:
使用API获取令牌对的速率:
获取使用价格馈送合同的代币对:
获得ERC20
批准ERC20
建立并签署交易

在本地运行示例:

ParaSwap SDK - ParaSwap软件开发包


您可以使用此SDK使用ERC-20代币进行交换或支付。

我们构建了一个示例dApp,可以在这里找到https://github.com/paraswap/demo-dapp

您也可以在以下网站查看一个实例:https://paraswap-sdk.netlify.com

ParaSwap SDK - ParaSwap软件开发包


此处提供API文档:

https://paraswapv2.docs.apiary.io

要使用ParaSwap SDK:

使用npm或yarn安装lib

yarn install paraswap
然后在Javascript文件上检索所有可用令牌的列表:
const {ParaSwap} = require("paraswap"); const paraswap = new ParaSwap();

ES6或TypeScript

import {ParaSwap} from "paraswap"; const paraswap = new ParaSwap();
使用API获取令牌对的速率:
const tokens = await paraSwap.getTokens();
获取使用价格馈送合同的代币对:
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);

其中priceRoute包含汇率和交易所之间的分布,请查看最优汇率类型以了解更多详细信息。

获得ERC20

这可用于无信任集成,

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

这是一个描述从价格查询到执行掉期的数据流的模式:

<ParaSwap SDK>

也可在https://paraswap-achirecture.netlify.com

批准ERC20
const paraSwap = new ParaSwap().setWeb3Provider(web3Provider);  const allowance = await paraSwap.getAllowance(userAddress, tokenAddress);
建立并签署交易
const paraSwap = new ParaSwap().setWeb3Provider(web3Provider);  const txHash = await paraSwap.approveToken(amount, userAddress, tokenAddress);
在本地运行示例:
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:

使用这两个env变量创建了一个.env文件:

PROVIDER_URL=YOUR_PROVIDRER_URL_OR_INFURA_URL NODE_ENV=production

运行

yarn install paraswap

对于本地开发,您可以运行

yarn dev

进行生产构建:

yarn build

它将在“dist”文件夹上生成一个生产版本

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/17391.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 !
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » ParaSwap SDK – ParaSwap软件开发包区块链毕设代写

提供最优质的资源集合

立即查看 了解详情