List Outputs
You can list all the outputs related to an account by calling the Account.outputs()
function.
Code Example
The following example will:
- Create an account manager.
- Get Alice's account which was created in the first guide.
- List all the outputs related to Alice's account.
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 if an output has only the address unlock condition, where the address belongs to the account in the Check Unlock Conditions how-to guide.
- Rust
- Nodejs
- Python
- Java
This how to guide is not available in your language of choice at the moment. Please feel free to browse more examples which may suit your requirements.
/**
* This example lists the outputs of the first account
*/
const getUnlockedManager = require('./account-manager');
async function run() {
try {
const manager = await getUnlockedManager();
const account = await manager.getAccount('Alice');
await account.sync();
const outputs = await account.outputs()
console.log('Listing Outputs:', outputs);
} catch (error) {
console.log('Error: ', error);
}
process.exit(0);
}
run();
You can run the example by running the following command from the wallet/bindings/nodejs/examples/
folder:
node 12a-list-outputs.js
from iota_wallet import IotaWallet
# In this example we will get outputs stored in the account
wallet = IotaWallet('./alice-database')
account = wallet.get_account('Alice')
# All outputs stored in the account
outputs = account.outputs()
print(f'Outputs: {outputs}')
# Only the unspent outputs in the account
unspent_outputs = account.outputs()
print(f'Unspent outputs: {unspent_outputs}')
You can run the example by running the following command from the binding/python/examples
folder:
python3 9-list-outputs.py
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
import org.iota.Wallet;
import org.iota.types.*;
import org.iota.types.account_methods.Outputs;
import org.iota.types.account_methods.SyncAccount;
import org.iota.types.exceptions.InitializeWalletException;
import org.iota.types.exceptions.WalletException;
import org.iota.types.ids.account.AccountAlias;
import org.iota.types.secret.StrongholdSecretManager;
public class ListOutputs {
public static void main(String[] args) throws WalletException, InterruptedException, InitializeWalletException {
// This example assumes that a wallet has already been created using the ´SetupWallet.java´ example.
// If you haven't run the ´SetupWallet.java´ example yet, you must run it first to be able to load the wallet as shown below:
Wallet wallet = new Wallet(new WalletConfig()
.withClientOptions(new ClientConfig().withNodes(Env.NODE))
.withSecretManager(new StrongholdSecretManager(Env.STRONGHOLD_PASSWORD, null, Env.STRONGHOLD_VAULT_PATH))
.withCoinType(CoinType.Shimmer)
.withStoragePath(Env.STORAGE_PATH)
);
// Get account and sync it with the registered node to ensure that its balances are up-to-date.
AccountHandle a = wallet.getAccount(new AccountAlias(Env.ACCOUNT_NAME));
a.syncAccount(new SyncAccount().withOptions(new SyncOptions()));
// Get outputs.
OutputData[] outputs = a.getOutputs(new Outputs());
// Print outputs.
for (OutputData o : outputs)
System.out.println(o);
// In case you are done and don't need the wallet instance anymore you can destroy the instance to clean up memory.
// For this, check out the ´DestroyWallet.java´ example.
}
}
Expected Output
- Rust
- Nodejs
- Python
- Java
This how to guide is not available in your language of choice at the moment. Please feel free to browse more examples which may suit your requirements.
Listing Outputs: [
{
outputId: '0x72240e6d6dc463e4dd962a2e34f2233a41b56a259c84faf895fbbb96820773050100',
metadata: {
blockId: '0x1106c1e0da5b2e10762fcf0ed3bc2a4790ffd2a81895afbc58df6b447c70ad3a',
transactionId: '0x72240e6d6dc463e4dd962a2e34f2233a41b56a259c84faf895fbbb9682077305',
outputIndex: 1,
isSpent: false,
milestoneIndexBooked: 972425,
milestoneTimestampBooked: 1662996908,
ledgerIndex: 974093
},
output: {
type: 5,
amount: '53600',
serialNumber: 4,
tokenScheme: [Object],
unlockConditions: [Array],
immutableFeatures: [Array]
},
isSpent: false,
address: {
type: 0,
pubKeyHash: '0xeed1e4e3e9e7555e2f1592594bf916523e7fef3a9a8c0d630a4934440b822647'
},
networkId: '1856588631910923207',
remainder: false,
chain: [ [Object], [Object], [Object], [Object], [Object] ]
},
[...]
]
Outputs:[
{
'outputId':'0xf4676daae96cf629c04d8d62989dec6d9dbbac221959d72c399729f92047ec140000',
'metadata':{
'blockId':'0x77b1fec7bd1ebb9ecfdf1ed9501dbf17acc4b1aa3889f310be95d5d82a5b5674',
'transactionId':'0xf4676daae96cf629c04d8d62989dec6d9dbbac221959d72c399729f92047ec14',
'outputIndex':0,
'isSpent':False,
'milestoneIndexBooked':1571314,
'milestoneTimestampBooked':1665991915,
'ledgerIndex':1571314
},
'output':{
'type':3,
'amount':'1000000000',
'unlockConditions':[
{
'type':0,
'address':{
'type':0,
'pubKeyHash':'0xf4d94c9f4e63d553c81e644225fa3bbc412f820c4eafd495aeb0bb05a29922b2'
}
}
]
},
'isSpent':False,
'address':{
'type':0,
'pubKeyHash':'0xf4d94c9f4e63d553c81e644225fa3bbc412f820c4eafd495aeb0bb05a29922b2'
},
'networkId':'1856588631910923207',
'remainder':False,
'chain':[
{
'hardened':True,
'bs':[
128,
0,
0,
44
]
},
{
'hardened':True,
'bs':[
128,
0,
16,
123
]
},
{
'hardened':True,
'bs':[
128,
0,
0,
0
]
},
{
'hardened':True,
'bs':[
128,
0,
0,
0
]
},
{
'hardened':True,
'bs':[
128,
0,
0,
0
]
}
]
}
]
Unspent outputs:[
{
'outputId':'0xf4676daae96cf629c04d8d62989dec6d9dbbac221959d72c399729f92047ec140000',
'metadata':{
'blockId':'0x77b1fec7bd1ebb9ecfdf1ed9501dbf17acc4b1aa3889f310be95d5d82a5b5674',
'transactionId':'0xf4676daae96cf629c04d8d62989dec6d9dbbac221959d72c399729f92047ec14',
'outputIndex':0,
'isSpent':False,
'milestoneIndexBooked':1571314,
'milestoneTimestampBooked':1665991915,
'ledgerIndex':1571314
},
'output':{
'type':3,
'amount':'1000000000',
'unlockConditions':[
{
'type':0,
'address':{
'type':0,
'pubKeyHash':'0xf4d94c9f4e63d553c81e644225fa3bbc412f820c4eafd495aeb0bb05a29922b2'
}
}
]
},
'isSpent':False,
'address':{
'type':0,
'pubKeyHash':'0xf4d94c9f4e63d553c81e644225fa3bbc412f820c4eafd495aeb0bb05a29922b2'
},
'networkId':'1856588631910923207',
'remainder':False,
'chain':[
{
'hardened':True,
'bs':[
128,
0,
0,
44
]
},
{
'hardened':True,
'bs':[
128,
0,
16,
123
]
},
{
'hardened':True,
'bs':[
128,
0,
0,
0
]
},
{
'hardened':True,
'bs':[
128,
0,
0,
0
]
},
{
'hardened':True,
'bs':[
128,
0,
0,
0
]
}
]
}
]
{
"outputId":"0xb23dc6681903672b76aae4f74c405fcd684c6fcf5d21fc367addcbafd0c3770c1a00",
"metadata":{
"blockId":"0xcfb891e37d261bf48381ec5fd7a6957396ce9296dab35d8111cc8bb4369dc2cd",
"transactionId":"0xb23dc6681903672b76aae4f74c405fcd684c6fcf5d21fc367addcbafd0c3770c",
"outputIndex":26,
"isSpent":false,
"milestoneIndexBooked":831306,
"milestoneTimestampBooked":1662290619,
"ledgerIndex":1351681
},
"output":{
"type":3,
"amount":"50600",
"unlockConditions":[
{
"type":0,
"address":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
},
{
"type":1,
"returnAddress":{
"type":0,
"pubKeyHash":"0x8297ac4149c80cca8225e5f2da36df89a93cd2998d7f6d488c97250a881e65af"
},
"amount":"50600"
},
{
"type":3,
"returnAddress":{
"type":0,
"pubKeyHash":"0x8297ac4149c80cca8225e5f2da36df89a93cd2998d7f6d488c97250a881e65af"
},
"unixTime":1662895377
}
]
},
"isSpent":false,
"address":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
},
"networkId":"1856588631910923207",
"remainder":false,
"chain":[
{
"hardened":true,
"bs":[
128,
0,
0,
44
]
},
{
"hardened":true,
"bs":[
128,
0,
16,
123
]
},
{
"hardened":true,
"bs":[
128,
0,
0,
0
]
},
{
"hardened":true,
"bs":[
128,
0,
0,
0
]
},
{
"hardened":true,
"bs":[
128,
0,
0,
0
]
}
]
}
{
"outputId":"0x94f6bdabbfc0b3f39961ffe7a19c3a26fde2908cce6b879beb4c20ed27cdad420000",
"metadata":{
"blockId":"0x6079cabb638789187cb372d521c033afdf15f52093cc1b922330fe81bb3574d3",
"transactionId":"0x94f6bdabbfc0b3f39961ffe7a19c3a26fde2908cce6b879beb4c20ed27cdad42",
"outputIndex":0,
"isSpent":false,
"milestoneIndexBooked":1350472,
"milestoneTimestampBooked":1664887705,
"ledgerIndex":1351681
},
"output":{
"type":3,
"amount":"50601",
"unlockConditions":[
{
"type":0,
"address":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
},
{
"type":1,
"returnAddress":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
},
"amount":"50600"
},
{
"type":3,
"returnAddress":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
},
"unixTime":1664887701
}
]
},
"isSpent":false,
"address":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
},
"networkId":"1856588631910923207",
"remainder":false,
"chain":[
{
"hardened":true,
"bs":[
128,
0,
0,
44
]
},
{
"hardened":true,
"bs":[
128,
0,
16,
123
]
},
{
"hardened":true,
"bs":[
128,
0,
0,
0
]
},
{
"hardened":true,
"bs":[
128,
0,
0,
0
]
},
{
"hardened":true,
"bs":[
128,
0,
0,
0
]
}
]
}
{
"outputId":"0xaccae1f4e78ee169d0fc1d99843e6cd417290da91aa62c696fa507d21fd245cc0200",
"metadata":{
"blockId":"0x8f9f12a968c32cc3d51e978f4de34252bc769ee7188e33a21f9351a7c1f122f3",
"transactionId":"0xaccae1f4e78ee169d0fc1d99843e6cd417290da91aa62c696fa507d21fd245cc",
"outputIndex":2,
"isSpent":false,
"milestoneIndexBooked":1350405,
"milestoneTimestampBooked":1664887370,
"ledgerIndex":1351681
},
"output":{
"type":3,
"amount":"2096427899",
"nativeTokens":[
{
"id":"0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0100000000",
"amount":"0x3233"
},
{
"id":"0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0200000000",
"amount":"0x3233"
},
{
"id":"0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0400000000",
"amount":"0x17"
}
],
"unlockConditions":[
{
"type":0,
"address":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
]
},
"isSpent":false,
"address":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
},
"networkId":"1856588631910923207",
"remainder":false,
"chain":[
{
"hardened":true,
"bs":[
128,
0,
0,
44
]
},
{
"hardened":true,
"bs":[
128,
0,
16,
123
]
},
{
"hardened":true,
"bs":[
128,
0,
0,
0
]
},
{
"hardened":true,
"bs":[
128,
0,
0,
0
]
},
{
"hardened":true,
"bs":[
128,
0,
0,
0
]
}
]
}