Get Address Balance
You can retrieve the outputs for any given address using the Client.basicOutputIds(queryParameters) function. You can then use the retrieved outputs to calculate the balance.
The following code example will:
- Create a
Client
which will connect to the Shimmer Testnet. - Create a
SecretManager
from a mnemonic. - Get outputs for the generated address.
- Add the total amount of native tokens and outputs.
- Log the results from step 4 to console.
Code Example
- Rust
- Nodejs
- Python
- Java
Dotenv
This example uses dotenv, which is not safe to use in production environments.
client/examples/02_get_address_balance.rs
loading...
Run the Example
Run the example by running the following command:
cargo run --example 02_get_address_balance --release
Dotenv
This example uses dotenv, which is not safe to use in production environments.
client/bindings/nodejs/examples/05_get_address_balance
loading...
You can run the example by running the following command from the bindings/node/examples/
folder:
node dist/05_get_address_balance.js
client/bindings/python/examples/05_get_address_balance.py
loading...
You can run the example by running the following command from the binding/python/examples
folder:
python3 05_get_address_balance.py
client/bindings/java/examples/src/GetAddressBalance.java
loading...
Expected Output
- Rust
- Nodejs
- Python
- Java
Outputs controlled by rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy
have: 2609275800i and nativetokens: [
NativeToken{
token_id: TokenId(0x085c6b799750bdf7e5a5c81144465a0676bc11dab74b997444ca369949341720e80100000000),
amount: 100
},
NativeToken{
token_id: TokenId(0x0822ceb3166ad125d310e6660f5fc292356f87f2f9566e982ea22154cec3847b3f0100000000),
amount: 100
},
NativeToken{
token_id: TokenId(0x08f708a29e9619e847916de76c2e167e87a704c235dcbd7cda018865be7f561b5a0100000000),
amount: 50
},
NativeToken{
token_id: TokenId(0x0808fb702d67fdb320b5959f152c0f962630515d904c71ed09447c341a6cc171de0100000000),
amount: 100
},
NativeToken{
token_id: TokenId(0x08f1802858831220b282ccc4c557676d61f79833869de378ce9a81f736976ce39f0100000000),
amount: 50
}
]
Outputs controlled by rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy have: 2609275800 glow and native tokens: {
'0x0808fb702d67fdb320b5959f152c0f962630515d904c71ed09447c341a6cc171de0100000000': 100,
'0x0822ceb3166ad125d310e6660f5fc292356f87f2f9566e982ea22154cec3847b3f0100000000': 100,
'0x085c6b799750bdf7e5a5c81144465a0676bc11dab74b997444ca369949341720e80100000000': 100,
'0x08f708a29e9619e847916de76c2e167e87a704c235dcbd7cda018865be7f561b5a0100000000': 50,
'0x08f1802858831220b282ccc4c557676d61f79833869de378ce9a81f736976ce39f0100000000': 50
}
Outputs controlled by rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy have
2609275800 glow and nativetokens: [
[
{
'id': '0x0808fb702d67fdb320b5959f152c0f962630515d904c71ed09447c341a6cc171de0100000000',
'amount': '0x64'
},
{
'id': '0x0822ceb3166ad125d310e6660f5fc292356f87f2f9566e982ea22154cec3847b3f0100000000',
'amount': '0x64'
},
{
'id': '0x085c6b799750bdf7e5a5c81144465a0676bc11dab74b997444ca369949341720e80100000000',
'amount': '0x64'
},
{
'id': '0x08f708a29e9619e847916de76c2e167e87a704c235dcbd7cda018865be7f561b5a0100000000',
'amount': '0x32'
}
],
[
{
'id': '0x08f1802858831220b282ccc4c557676d61f79833869de378ce9a81f736976ce39f0100000000',
'amount': '0x32'
}
]
]
total balance: 1900755293
native tokens: {0x0833b41872b4ef228c10a99456fb08088a52a71f3ff23330287f6c8978bc5dd6df0100000000=100, 0x089c130fa264a23492f5876e4c2673154689fa8e30945c7b60c59050b20336d2b70100000000=50, 0x083c39ef7bd9a2eb640df6a36319a7fd51d4ca190ffd5d14572c9ebb54bdc6ecab0200000000=69, 0x083118235071d4013edd2315210626ca85cf27e961a9670d81c30716dd0058a8220100000000=50, 0x08f708a29e9619e847916de76c2e167e87a704c235dcbd7cda018865be7f561b5a0200000000=32, 0x08f7763ffc30099b089045e06a4a24047787510cd01310b42fec9ca006267d4be80100000000=50}