创新互联Moralis教程:Moralis账户

所有方法都扩展自 ​Moralis.SolanaAPI.account

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、成都做网站、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的遵义网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

balance

返回地址的 SOL 余额。

选项:

network​:要从中获取数据的网络集群。 有效值列在支持的网络上。 默认值主网。

address​:用户地址(即 6XU36wCxWobLx5Rtsb58kmgAJKVYmmVqy4SHXxENAyAe)。 如果指定,则附加到查询的用户将被忽略,而是使用地址。

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

// get mainnet SOL balance for the current user
const solBalance = await Moralis.SolanaAPI.account.balance();

// get devnet SOL balance for a given address
const options = {
  network: "devnet",
  address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
};
const solBalance = await Moralis.SolanaAPI.account.balance(options);
import { useMoralisSolanaApi, useMoralisSolanaCall } from "react-moralis";

const { account } = useMoralisSolanaApi();

// get mainnet SOL balance for the current user
const { fetch, data, isLoading } = useMoralisSolanaCall(account.balance);

// get devnet SOL balance for a given address
const options = {
  network: "devnet",
  address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
};
const { fetch, data, isLoading } = useMoralisSolanaCall(
  account.balance,
  options
);
curl -X 'GET' \
  'https://solana-gateway.moralis.io/account/devnet/6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe/balance' \
  -H 'accept: application/json' \
  -H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.SolanaApi.Models;
using Moralis.SolanaApi;
using MoralisWeb3ApiSdk;

  public async void GetSolNativeBalance()
  {
    NativeBalance solBalance = await MoralisSolanaClient.SolanaApi.Account.Balance(NetworkTypes.mainnet, "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe");
    print(solBalance);
  }

示例结果

{
  "lamports": "500000000",
  "solana": "0.5"
}

getSPL

返回地址的 SPL 代币余额。

选项:

  • network​:要从中获取数据的网络集群。 有效值列在支持的网络上。 默认值主网。
  • address​:用户地址(即 HsXZnAba2...)。 如果指定,则附加到查询的用户将被忽略,而是使用地址。

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

// get mainnet SPL token balance for the current user
const tokenBalance = await Moralis.SolanaAPI.account.getSPL();

// get devnet SPL token balance for a given address
const options = {
  network: "devnet",
  address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
};
const tokenBalance = await Moralis.SolanaAPI.account.getSPL(options);
import { useMoralisSolanaApi, useMoralisSolanaCall } from "react-moralis";

const { account } = useMoralisSolanaApi();

// get mainnet SPL token balance for the current user
const { fetch, data, isLoading } = useMoralisSolanaCall(account.getSPL);

// get devnet SPL token balance for a given address
const options = {
  network: "devnet",
  address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
};
const { fetch, data, isLoading } = useMoralisSolanaCall(
  account.getSPL,
  options
);
curl -X 'GET' \
  'https://solana-gateway.moralis.io/account/devnet/6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe/tokens' \
  -H 'accept: application/json' \
  -H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.SolanaApi.Models;
using Moralis.SolanaApi;
using MoralisWeb3ApiSdk;

  public async void GetSPLTokens()
  {
    List spltokens = await MoralisSolanaClient.SolanaApi.Account.GetSplTokens(NetworkTypes.mainnet, "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe");
    foreach(SplTokenBalanace spltoken in spltokens){
      print(spltoken);
   }
  }

示例结果

[
  {
    associatedTokenAddress: "Dpmpwm93Amvj4uEFpYhjv8ZzfpgARq6zxKTi6mrj97gW",
    mint: "BXWuzb3jEuGsGUe29xdApu8Z3jVgrFbr3wWdsZmLWYk9",
    amountRaw: "100000000000",
    amount: "100",
    decimals: "9",
  },
];

getNFTs

返回地址的 SPL NFT 余额。

选项:

  • network​:要从中获取数据的网络集群。 有效值列在支持的网络上。 默认值主网。
  • address​:用户地址(即 HsXZnAba2...)。 如果指定,则附加到查询的用户将被忽略,而是使用地址。

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

// get mainnet SPL NFT balance for the current user
const nftBalance = await Moralis.SolanaAPI.account.getNFTs();

// get devnet SPL NFT balance for a given address
const options = {
  network: "devnet",
  address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
};
const nftBalance = await Moralis.SolanaAPI.account.getNFTs(options);
import { useMoralisSolanaApi, useMoralisSolanaCall } from "react-moralis";

const { account } = useMoralisSolanaApi();

// get mainnet SPL NFT balance for the current user
const { fetch, data, isLoading } = useMoralisSolanaCall(account.getNFTs);

// get devnet SPL NFT balance for a given address
const options = {
  network: "devnet",
  address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
};
const { fetch, data, isLoading } = useMoralisSolanaCall(
  account.getNFTs,
  options
);
curl -X 'GET' \
  'https://solana-gateway.moralis.io/account/devnet/6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe/nft' \
  -H 'accept: application/json' \
  -H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.SolanaApi.Models;
using Moralis.SolanaApi;
using MoralisWeb3ApiSdk;

  public async void GetSPLNft()
  {
    List SplNFTbal = await MoralisSolanaClient.SolanaApi.Account.GetNFTs(NetworkTypes.mainnet, "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe");
    foreach(SplNft splnft in SplNFTbal){
      print(splnft);
    }
  }

示例结果

[
  {
    associatedTokenAddress: "Dpmpwm93Amvj4uEFpYhjv8ZzfpgARq6zxKTi6mrj97gW",
    mint: "BXWuzb3jEuGsGUe29xdApu8Z3jVgrFbr3wWdsZmLWYk9",
    amountRaw: "100000000000",
    amount: "100",
    decimals: "9",
  },
];

getPortfolio

返回地址的投资组合(SOL 余额、SPL 代币余额、SPL NFT 余额)。

选项:

  • network​:要从中获取数据的网络集群。 有效值列在支持的网络上。 默认值主网。
  • address​:用户地址(即 HsXZnAba2...)。 如果指定,则附加到查询的用户将被忽略,而是使用地址。

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

// get mainnet NFT balance for the current user
const portfolio = await Moralis.SolanaAPI.account.getPortfolio();

// get devnet NFT balance for a given address
const options = {
  network: "devnet",
  address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
};
const portfolio = await Moralis.SolanaAPI.account.getPortfolio(options);
import { useMoralisSolanaApi, useMoralisSolanaCall } from "react-moralis";

const { account } = useMoralisSolanaApi();

// get mainnet SPL NFT balance for the current user
const { fetch, data, isLoading } = useMoralisSolanaCall(account.getPortfolio);

// get devnet SPL NFT balance for a given address
const options = {
  network: "devnet",
  address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
};
const { fetch, data, isLoading } = useMoralisSolanaCall(
  account.getPortfolio,
  options
);
curl -X 'GET' \
  'https://solana-gateway.moralis.io/account/devnet/6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe/portfolio' \
  -H 'accept: application/json' \
  -H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.SolanaApi.Models;
using Moralis.SolanaApi;
using MoralisWeb3ApiSdk;

  public async void GetSPLPortfolioBal()
  {
    Portfolio PortfolioBal = await MoralisSolanaClient.SolanaApi.Account.GetPortfolio(NetworkTypes.mainnet, "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe");
    print(PortfolioBal);
  }

示例结果

{
  "nativeBalance": {
    "lamports": "6000000000",
    "solana": "6"
  },
  "nfts": [
    {
      "associatedTokenAddress": "6Fk96aAvPhV9gZvGXp9mMw1YwiScPX3pm1RwWn11eGrQ",
      "mint": "BpCcCVU4pK2rcvgduCzScaBhqKEKaMukcejkDhJWRyPv"
    }
  ],
  "tokens": [
    {
      "associatedTokenAddress": "Dpmpwm93Amvj4uEFpYhjv8ZzfpgARq6zxKTi6mrj97gW",
      "mint": "BXWuzb3jEuGsGUe29xdApu8Z3jVgrFbr3wWdsZmLWYk9",
      "amountRaw": "100000000000",
      "amount": "100",
      "decimals": "9"
    }
  ]
}

网站题目:创新互联Moralis教程:Moralis账户
转载源于:http://www.shufengxianlan.com/qtweb/news44/285294.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

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