Moralis Web3API.defi

2022-05-10 14:17 更新

getPairAddress(新)

獲取并返回提供的 token0+token1 組合的對數(shù)據(jù)(異步)。

token0 和 token1 選項是可互換的(即 token0=WETH 和 token1=USDT 或 token0=USDT 和 token1=WETH 沒有不同的結(jié)果)。

選項:

  • ?chain?(可選):從中獲取數(shù)據(jù)的區(qū)塊鏈。 有效值列在支持的鏈上。 默認值 Eth。
  • ?to_date?(可選):獲取該日期的配對地址(momentjs 接受的任何格式)提供參數(shù)“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?來實現(xiàn)

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());
  }

示例結(jié)果

{
  "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?(可選):從中獲取數(shù)據(jù)的區(qū)塊鏈。 有效值列在支持的鏈上。 默認值 Eth。
  • ?to_date?(可選):獲取到此日期的儲備(momentjs 接受的任何格式)提供參數(shù)“to_block”或“to_date”如果提供了“to_date”和“to_block”,將使用“to_block”。
  • ?to_block?(可選):獲取此區(qū)塊號的儲備
  • ?pair_address?(必填):流動性對地址

你可以使用?JS?、?React?、?curl?、?Unity?來實現(xiàn)

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());
  }

示例結(jié)果

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


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號