创新互联Moralis教程:MoralisWeb3API.defi

getPairAddress(新)

获取并返回提供的 token0+token1 组合的对数据(异步)。

公司主营业务:做网站、网站建设、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联推出邵原免费做网站回馈大家。

token0 和 token1 选项是可互换的(即 token0=WETH 和 token1=USDT 或 token0=USDT 和 token1=WETH 没有不同的结果)。

选项:

  • chain​(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。
  • to_date​(可选):获取该日期的配对地址(momentjs 接受的任何格式)提供参数“to_block”或“to_date”如果提供了“to_date”和“to_block”,则将使用“to_block”。
  • to_block ​(可选):获取此块号处的对地址
  • exchange​(必填):代币交易所的工厂名称或地址。 可用值:uniswapv2、uniswapv3、sushiswapv2、pancakeswapv2、pancakeswapv1、quickswap
  • token0_address​(必填):Token0 地址
  • token1_address​(必填):Token1 地址

你可以使用​JS​、​React​、​curl​、​Unity​来实现

const options = {
  token0_address: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
  token1_address: "0xe9e7cea3dedca5984780bafc599bd69add087d56",
  exchange: "pancakeswapv2",
  chain: "bsc",
};
const pairAddress = await Moralis.Web3API.defi.getPairAddress(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";

const Web3Api = useMoralisWeb3Api();

const fetchPairAddress = async () => {
  const options = {
    token0_address: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
    token1_address: "0xe9e7cea3dedca5984780bafc599bd69add087d56",
    exchange: "pancakeswapv2",
    chain: "bsc",
  };
  const pairAddress = await Web3Api.defi.getPairAddress(options);
  console.log(pairAddress);
};
curl -X 'GET' \
  'https://deep-index.moralis.io/api/v2/0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c/0xe9e7cea3dedca5984780bafc599bd69add087d56/pairAddress?chain=bsc&exchange=pancakeswapv2' \
  -H 'accept: application/json' \
  -H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;

  public async void fetchPairAddress()
  {
    ReservesCollection pairAddress = await MoralisInterface.GetClient().Web3Api.Defi.GetPairAddress(exchange:"pancakeswapv2" , token0Address:"0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c" , token1Address:"0xe9e7cea3dedca5984780bafc599bd69add087d56", chain:ChainList.bsc);
    print(pairAddress.ToJson());
  }

示例结果

{
  "token0": {
    "address": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
    "name": "Wrapped BNB",
    "symbol": "WBNB",
    "logo": null,
    "logo_hash": null,
    "thumbnail": null,
    "decimals": "18",
    "block_number": "8242108",
    "validated": 1
  },
  "token1": {
    "address": "0xe9e7cea3dedca5984780bafc599bd69add087d56",
    "name": "BUSD Token",
    "symbol": "BUSD",
    "logo": null,
    "logo_hash": null,
    "thumbnail": null,
    "decimals": "18",
    "block_number": "8242108",
    "validated": 1
  },
  "pairAddress": "0x58f876857a02d6762e0101bb5c46a8c1ed44dc16"
}

getPairReserves(新)

获取给定对地址的流动性储备(异步)。

选项:

  • chain​(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。
  • to_date​(可选):获取到此日期的储备(momentjs 接受的任何格式)提供参数“to_block”或“to_date”如果提供了“to_date”和“to_block”,将使用“to_block”。
  • to_block​(可选):获取此区块号的储备
  • pair_address​(必填):流动性对地址

你可以使用​JS​、​React​、​curl​、​Unity​来实现

const options = {
  pair_address: "0x58f876857a02d6762e0101bb5c46a8c1ed44dc16",
  chain: "bsc",
};
const reserves = await Moralis.Web3API.defi.getPairReserves(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";

const Web3Api = useMoralisWeb3Api();

const fetchPairReserves = async () => {
  const options = {
    pair_address: "0x58f876857a02d6762e0101bb5c46a8c1ed44dc16",
    chain: "bsc",
  };
  const reserves = await Web3Api.defi.getPairReserves(options);
  console.log(reserves);
};
curl -X 'GET' \
  'https://deep-index.moralis.io/api/v2/0x58f876857a02d6762e0101bb5c46a8c1ed44dc16/reserves?chain=bsc' \
  -H 'accept: application/json' \
  -H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;

  public async void fetchPairReserves()
  {
    ReservesCollection reserves = await MoralisInterface.GetClient().Web3Api.Defi.GetPairReserves(pairAddress:"0x58f876857a02d6762e0101bb5c46a8c1ed44dc16" , ChainList.bsc);
    print(reserves.ToJson());
  }

示例结果

{
  "reserve0": "412342701316335044600434",
  "reserve1": "156921226397095561306301741"
}

网站名称:创新互联Moralis教程:MoralisWeb3API.defi
当前链接:http://www.mswzjz.cn/qtweb/news21/539371.html

攀枝花网站建设、攀枝花网站运维推广公司-贝锐智能,是专注品牌与效果的网络营销公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 贝锐智能