举报投诉联系我们 手机版 热门标签 鳄鱼CMS
您的位置:鳄鱼CMS > Moralis Web3API.defi

Moralis Web3API.defi

2023-04-02 13:31 Moralis Web3API.defi

 Moralis Web3API.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"
}


阅读全文
以上是鳄鱼CMS为你收集整理的 Moralis Web3API.defi全部内容。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。
相关文章
© 2024 鳄鱼CMS eyucms.com 版权所有 联系我们