Check Balance
You can retrieve the balance for any account you created by calling the
Account.balance()
function. Bear in mind that you should always sync the account with the node to get the latest
transactions.
You can request test funds from the Shimmer Testnet Faucet.
Code Example
The following example will:
- Create an account manager.
- Get Alice's account which was created in the first guide.
- Sync the account with the node to get the latest transactions.
- Request the account's balance.
Outputs may have multiple UnlockConditions, which may require returning some or all of the transferred amount. The outputs could also expire if not claimed in time, or may not be unlockable for a predefined period.
To get outputs with only the AddressUnlockCondition
, you should synchronize with the option syncOnlyMostBasicOutputs: true
.
If you are synchronizing outputs with other unlock conditions, you should check the unlock conditions carefully before crediting users any balance.
You can find an example illustrating how to check whether an output has only the address unlock condition and whether this address belongs to the account in the Check Unlock Conditions how-to guide.
- Rust
- Nodejs
- Python
- Java
This example uses dotenv, which is not safe for use in production environments.
loading...
Run the example by running the following command:
cargo run --example get_balance --release
loading...
You can run the example by running the following command from the wallet/bindings/nodejs/examples/
folder:
node 3-check-balance.js
loading...
You can run the example by running the following command from the binding/python/examples
folder:
python3 2-check-balance.py
loading...
Expected Output
- Rust
- Nodejs
- Python
- Java
AccountBalance{
base_coin: BaseCoinBalance{
total: 100000000000,
available: 100000000000
},
required_storage_deposit: 213000,
native_tokens: [
],
nfts: [
],
aliases: [
],
foundries: [
],
potentially_locked_outputs: {
}
}
Synced: {
'baseCoin': {
'total': '3490057203',
'available': '3490057203'
},
'requiredStorageDeposit': '98250300',
'nativeTokens': [
{
'tokenId': '0x08b83d49922e341d2cb45159707cfafdc9dc8fdb9d119543480dbaa5773eed8c4a0100000000',
'total': '0x64',
'available': '0x64'
}
],
'nfts': [
'0xceae643ff7c112a3adce8f55f7953ba0707ade21256a7a09068c0b47f7c62c5b',
'0x1e808b7c6e603aaeb5f718881a74fedae72981ac7d5f0294eb561cad0e653566',
'0x77133189021f50d8d66e0678e553af9f46a832a24239653d3555edb8dc859e1f',
'0x17f97185f80fa56eab974de6b7bbb80fa812d4e8e37090d166a0a41da129cebc',
'0x1b670afba8d59a445cbaf167f1fda05879362e3ea034f5c4a0979fbeb5a3964b',
'0x3f0e11e9d9f48a57d0fba43d7d1158ee673cb8055f80a5ce45ad174c962c0d8a',
'0xdc8be91d779aac048aa9001ab99ecf12cf62a4701185a95f6206a1a201bfbe7c'
],
'aliases': [
],
'foundries': [
],
'potentiallyLockedOutputs': {
'0x8dd4f722a18f3b5822216e856a98ea480fbfaa205f10c08d36dc5ab21efcc8355600': False
}[
...
]
]
Balance: {
'baseCoin': {
'total': '3490057203',
'available': '3490057203'
},
'requiredStorageDeposit': '98250300',
'nativeTokens': [
{
'tokenId': '0x08b83d49922e341d2cb45159707cfafdc9dc8fdb9d119543480dbaa5773eed8c4a0100000000',
'total': '0x64',
'available': '0x64'
}
],
'nfts': [
'0xceae643ff7c112a3adce8f55f7953ba0707ade21256a7a09068c0b47f7c62c5b',
'0x1e808b7c6e603aaeb5f718881a74fedae72981ac7d5f0294eb561cad0e653566',
'0x77133189021f50d8d66e0678e553af9f46a832a24239653d3555edb8dc859e1f',
'0x17f97185f80fa56eab974de6b7bbb80fa812d4e8e37090d166a0a41da129cebc',
'0x1b670afba8d59a445cbaf167f1fda05879362e3ea034f5c4a0979fbeb5a3964b',
'0x3f0e11e9d9f48a57d0fba43d7d1158ee673cb8055f80a5ce45ad174c962c0d8a',
'0xdc8be91d779aac048aa9001ab99ecf12cf62a4701185a95f6206a1a201bfbe7c'
],
'aliases': [
],
'foundries': [
],
'potentiallyLockedOutputs': {
'0xa10af6cc21fa0b1b67962af7082eb25d8b4aafe50fedda469179f469ab5e33be5300': False,
[...]
}
]
{
"baseCoin": {
"total": "2096947200",
"available": "2096947200"
},
"requiredStorageDeposit": "323500",
"nativeTokens": [
{
"tokenId": "0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0100000000",
"total": "0x3233",
"available": "0x3233"
},
{
"tokenId": "0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0200000000",
"total": "0x3233",
"available": "0x3233"
},
{
"tokenId": "0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0300000000",
"total": "0x17",
"available": "0x17"
}
],
"nfts": [
"0x60b3a254d7704773c298882b7b93f70d12e1cc4a0b91d0b1037f6ea64d76b249",
"0xf95f4d5344217a2ba19a6c19a47f97d267edf8c4d76a7b8c08072ad35acbebbe"
],
"aliases": [
"0x429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef"
],
"foundries": [
"0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0300000000",
"0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0100000000"
],
"potentiallyLockedOutputs": {}
}