๐Ÿ’ฐ
SolanaAPI.account
The account topic extends the namespace Moralis.SolanaAPI
All the methods extend from Moralis.SolanaAPI.account

balance

Returns SOL balance of an address.

Options:

  • network: The network cluster to get data from. Valid values are listed on the Supported Networks. Default value mainnet.
  • address: A user address (i.e. 6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe). If specified, the user attached to the query is ignored and the address will be used instead.
JS
React
curl
Unity
1
// get mainnet SOL balance for the current user
2
const solBalance = await Moralis.SolanaAPI.account.balance();
3
โ€‹
4
// get devnet SOL balance for a given address
5
const options = {
6
network: "devnet",
7
address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
8
};
9
const solBalance = await Moralis.SolanaAPI.account.balance(options);
Copied!
1
import { useMoralisSolanaApi, useMoralisSolanaCall } from "react-moralis";
2
โ€‹
3
const { account } = useMoralisSolanaApi();
4
โ€‹
5
// get mainnet SOL balance for the current user
6
const { fetch, data, isLoading } = useMoralisSolanaCall(account.balance);
7
โ€‹
8
// get devnet SOL balance for a given address
9
const options = {
10
network: "devnet",
11
address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
12
};
13
const { fetch, data, isLoading } = useMoralisSolanaCall(
14
account.balance,
15
options
16
);
Copied!
1
curl -X 'GET' \
2
'https://solana-gateway.moralis.io/account/devnet/6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe/balance' \
3
-H 'accept: application/json' \
4
-H 'X-API-Key: MY-API-KEY'
Copied!
1
using MoralisUnity;
2
using MoralisUnity.SolanaApi.Models;
3
using UnityEngine;
4
โ€‹
5
public class Example
6
{
7
public async void GetSolNativeBalance()
8
{
9
NativeBalance solBalance = await Moralis.SolanaApi.Account.Balance(NetworkTypes.mainnet, "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe");
10
Debug.Log(solBalance);
11
}
12
}
Copied!

Example result:

1
{
2
"lamports": "500000000",
3
"solana": "0.5"
4
}
Copied!

getSPL

Returns SPL token balance of an address.

Options:

  • network: The network cluster to get data from. Valid values are listed on the Supported Networks. Default value mainnet.
  • address: A user address (i.e. HsXZnAba2...). If specified, the user attached to the query is ignored and the address will be used instead.
JS
React
curl
Unity
1
// get mainnet SPL token balance for the current user
2
const tokenBalance = await Moralis.SolanaAPI.account.getSPL();
3
โ€‹
4
// get devnet SPL token balance for a given address
5
const options = {
6
network: "devnet",
7
address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
8
};
9
const tokenBalance = await Moralis.SolanaAPI.account.getSPL(options);
Copied!
1
import { useMoralisSolanaApi, useMoralisSolanaCall } from "react-moralis";
2
โ€‹
3
const { account } = useMoralisSolanaApi();
4
โ€‹
5
// get mainnet SPL token balance for the current user
6
const { fetch, data, isLoading } = useMoralisSolanaCall(account.getSPL);
7
โ€‹
8
// get devnet SPL token balance for a given address
9
const options = {
10
network: "devnet",
11
address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
12
};
13
const { fetch, data, isLoading } = useMoralisSolanaCall(
14
account.getSPL,
15
options
16
);
Copied!
1
curl -X 'GET' \
2
'https://solana-gateway.moralis.io/account/devnet/6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe/tokens' \
3
-H 'accept: application/json' \
4
-H 'X-API-Key: MY-API-KEY'
Copied!
1
using MoralisUnity;
2
using MoralisUnity.SolanaApi.Models;
3
using System.Collections.Generic;
4
using UnityEngine;
5
โ€‹
6
public class Example
7
{
8
public async void GetSPLTokens()
9
{
10
List<SplTokenBalanace> spltokens = await Moralis.SolanaApi.Account.GetSplTokens(NetworkTypes.mainnet, "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe");
11
foreach (SplTokenBalanace spltoken in spltokens)
12
{
13
Debug.Log(spltoken);
14
}
15
}
16
}
Copied!

Example result:

1
[
2
{
3
associatedTokenAddress: "Dpmpwm93Amvj4uEFpYhjv8ZzfpgARq6zxKTi6mrj97gW",
4
mint: "BXWuzb3jEuGsGUe29xdApu8Z3jVgrFbr3wWdsZmLWYk9",
5
amountRaw: "100000000000",
6
amount: "100",
7
decimals: "9",
8
},
9
];
Copied!

getNFTs

Returns SPL NFT balance of an address.

Options:

  • network: The network cluster to get data from. Valid values are listed on Supported Networks. Default value mainnet.
  • address: A user address (i.e. HsXZnAba2...). If specified, the user attached to the query is ignored and the address will be used instead.
JS
React
curl
Unity
1
// get mainnet SPL NFT balance for the current user
2
const nftBalance = await Moralis.SolanaAPI.account.getNFTs();
3
โ€‹
4
// get devnet SPL NFT balance for a given address
5
const options = {
6
network: "devnet",
7
address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
8
};
9
const nftBalance = await Moralis.SolanaAPI.account.getNFTs(options);
Copied!
1
import { useMoralisSolanaApi, useMoralisSolanaCall } from "react-moralis";
2
โ€‹
3
const { account } = useMoralisSolanaApi();
4
โ€‹
5
// get mainnet SPL NFT balance for the current user
6
const { fetch, data, isLoading } = useMoralisSolanaCall(account.getNFTs);
7
โ€‹
8
// get devnet SPL NFT balance for a given address
9
const options = {
10
network: "devnet",
11
address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
12
};
13
const { fetch, data, isLoading } = useMoralisSolanaCall(
14
account.getNFTs,
15
options
16
);
Copied!
1
curl -X 'GET' \
2
'https://solana-gateway.moralis.io/account/devnet/6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe/nft' \
3
-H 'accept: application/json' \
4
-H 'X-API-Key: MY-API-KEY'
Copied!
1
using MoralisUnity;
2
using MoralisUnity.SolanaApi.Models;
3
using System.Collections.Generic;
4
using UnityEngine;
5
โ€‹
6
public class Example
7
{
8
public async void GetSPLNft()
9
{
10
List<SplNft> SplNFTbal = await Moralis.SolanaApi.Account.GetNFTs(NetworkTypes.mainnet, "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe");
11
foreach (SplNft splnft in SplNFTbal)
12
{
13
Debug.Log(splnft);
14
}
15
}
16
}
Copied!

Example result:

1
[
2
{
3
associatedTokenAddress: "Dpmpwm93Amvj4uEFpYhjv8ZzfpgARq6zxKTi6mrj97gW",
4
mint: "BXWuzb3jEuGsGUe29xdApu8Z3jVgrFbr3wWdsZmLWYk9",
5
amountRaw: "100000000000",
6
amount: "100",
7
decimals: "9",
8
},
9
];
Copied!

getPortfolio

Returns the portfolio (SOL balance, SPL token blanace, SPL NFT balance) of an address.

Options:

  • network: The network cluster to get data from. Valid values are listed on Supported Networks. Default value mainnet.
  • address: A user address (i.e. HsXZnAba2...). If specified, the user attached to the query is ignored and the address will be used instead.
JS
React
curl
Unity
1
// get mainnet NFT balance for the current user
2
const portfolio = await Moralis.SolanaAPI.account.getPortfolio();
3
โ€‹
4
// get devnet NFT balance for a given address
5
const options = {
6
network: "devnet",
7
address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
8
};
9
const portfolio = await Moralis.SolanaAPI.account.getPortfolio(options);
Copied!
1
import { useMoralisSolanaApi, useMoralisSolanaCall } from "react-moralis";
2
โ€‹
3
const { account } = useMoralisSolanaApi();
4
โ€‹
5
// get mainnet SPL NFT balance for the current user
6
const { fetch, data, isLoading } = useMoralisSolanaCall(account.getPortfolio);
7
โ€‹
8
// get devnet SPL NFT balance for a given address
9
const options = {
10
network: "devnet",
11
address: "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe",
12
};
13
const { fetch, data, isLoading } = useMoralisSolanaCall(
14
account.getPortfolio,
15
options
16
);
Copied!
1
curl -X 'GET' \
2
'https://solana-gateway.moralis.io/account/devnet/6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe/portfolio' \
3
-H 'accept: application/json' \
4
-H 'X-API-Key: MY-API-KEY'
Copied!
1
using MoralisUnity;
2
using MoralisUnity.SolanaApi.Models;
3
using UnityEngine;
4
โ€‹
5
public class Example
6
{
7
public async void GetSPLPortfolioBal()
8
{
9
Portfolio PortfolioBal = await Moralis.SolanaApi.Account.GetPortfolio(NetworkTypes.mainnet, "6XU36wCxWobLx5Rtsb58kmgAJKVYmMVqy4SHXxENAyAe");
10
Debug.Log(PortfolioBal);
11
}
12
}
Copied!

Example result:

1
{
2
"nativeBalance": {
3
"lamports": "6000000000",
4
"solana": "6"
5
},
6
"nfts": [
7
{
8
"associatedTokenAddress": "6Fk96aAvPhV9gZvGXp9mMw1YwiScPX3pm1RwWn11eGrQ",
9
"mint": "BpCcCVU4pK2rcvgduCzScaBhqKEKaMukcejkDhJWRyPv"
10
}
11
],
12
"tokens": [
13
{
14
"associatedTokenAddress": "Dpmpwm93Amvj4uEFpYhjv8ZzfpgARq6zxKTi6mrj97gW",
15
"mint": "BXWuzb3jEuGsGUe29xdApu8Z3jVgrFbr3wWdsZmLWYk9",
16
"amountRaw": "100000000000",
17
"amount": "100",
18
"decimals": "9"
19
}
20
]
21
}
Copied!