List Transactions
You can list all the transactions related to an account by calling the Account.transactions()
function after you
have instantiated the account. Bear in mind that you will need to call the Account.sync()
function to get the latest
information from the node.
Code Example
The following example will:
- Create an account manager.
- Get Alice's account which was created in the first guide.
- Sync the account to get the latest transactions from the node.
- List the transactions using the
Account.transactions()
function.
- 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 transactions 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 transactions = await account.transactions()
console.log('Listing Transactions:', transactions);
} 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 12c-list-transactions.js
from iota_wallet import IotaWallet
# In this example we will list the sent transactions
wallet = IotaWallet('./alice-database')
account = wallet.get_account('Alice')
wallet.set_stronghold_password("some_hopefully_secure_password")
# All transactions sent from the the account
transactions = account.transactions()
print(f'Transactions: {transactions}')
# Pending transactions
pending_transactions = account.pending_transactions()
print(f'Pending transactions: {pending_transactions}')
You can run the example by running the following command from the binding/python/examples
folder:
python3 11-list-transactions.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.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 ListTransactions {
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 transactions.
Transaction[] transactions = a.getTransactions();
// Print transactions.
for (Transaction tx : transactions)
System.out.println(tx.toString());
// 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 Transactions: [
{
payload: { type: 6, essence: [Object], unlocks: [Array] },
blockId: '0x7bebed05d7687206a24e0461305af41900fe57f4480bff08ac79d0f193f99a63',
inclusionState: 'Confirmed',
timestamp: '1663005355019',
transactionId: '0xc4cd87bb0f33f2be15fab5454628ca21dc7f516120e7ddae8f87f4308b123412',
networkId: '1856588631910923207',
incoming: false,
note: null
}
[...]
]
Transactions:[
{
'payload':{
'type':6,
'essence':{
'type':1,
'networkId':'1856588631910923207',
'inputs':[
{
'type':0,
'transactionId':'0x79edb042038431009408d734a337f6fae9dcec97b0d7572665d0c184ea74b82f',
'transactionOutputIndex':0
},
{
'type':0,
'transactionId':'0xf4676daae96cf629c04d8d62989dec6d9dbbac221959d72c399729f92047ec14',
'transactionOutputIndex':0
}
],
'inputsCommitment':'0x51a6fe8c7670746c2a45f620be0055c1853f84599c68490a7258ee3c41ba2332',
'outputs':[
{
'type':3,
'amount':'50600',
'unlockConditions':[
{
'type':0,
'address':{
'type':0,
'pubKeyHash':'0xf8ba764448d689422aa59a5c5dc97108450a29cb8956208f631ab4a82338468a'
}
}
]
},
{
'type':3,
'amount':'1000000001',
'unlockConditions':[
{
'type':0,
'address':{
'type':0,
'pubKeyHash':'0xf4d94c9f4e63d553c81e644225fa3bbc412f820c4eafd495aeb0bb05a29922b2'
}
}
]
}
]
},
'unlocks':[
{
'type':0,
'signature':{
'type':0,
'publicKey':'0xee4164cca9a455db3164ec2a3c3ebc2db57aec8c4cb3231c3dc6cda0c700e1bd',
'signature':'0xf474de893c5a47d9114d2a95f1bd0e4c83b464e8a17886a07ea8d04046949a17dbb8173183c08d4cadbe530c7f42a65fa3286a5f28644a76cf59f6411a04220f'
}
},
{
'type':1,
'reference':0
}
]
},
'blockId':'0x99d29eceb87b44664361f7faf9d8f3b072c6e3e890953fdf956f6d148d9b04b2',
'inclusionState':'Pending',
'timestamp':'1665992931904',
'transactionId':'0xeed7357bf0c0bbdca809e5e537af5a10872e488b26a157af78c68e104420ad75',
'networkId':'1856588631910923207',
'incoming':False,
'note':None
}
]
Pending transactions:[
{
'payload':{
'type':6,
'essence':{
'type':1,
'networkId':'1856588631910923207',
'inputs':[
{
'type':0,
'transactionId':'0x79edb042038431009408d734a337f6fae9dcec97b0d7572665d0c184ea74b82f',
'transactionOutputIndex':0
},
{
'type':0,
'transactionId':'0xf4676daae96cf629c04d8d62989dec6d9dbbac221959d72c399729f92047ec14',
'transactionOutputIndex':0
}
],
'inputsCommitment':'0x51a6fe8c7670746c2a45f620be0055c1853f84599c68490a7258ee3c41ba2332',
'outputs':[
{
'type':3,
'amount':'50600',
'unlockConditions':[
{
'type':0,
'address':{
'type':0,
'pubKeyHash':'0xf8ba764448d689422aa59a5c5dc97108450a29cb8956208f631ab4a82338468a'
}
}
]
},
{
'type':3,
'amount':'1000000001',
'unlockConditions':[
{
'type':0,
'address':{
'type':0,
'pubKeyHash':'0xf4d94c9f4e63d553c81e644225fa3bbc412f820c4eafd495aeb0bb05a29922b2'
}
}
]
}
]
},
'unlocks':[
{
'type':0,
'signature':{
'type':0,
'publicKey':'0xee4164cca9a455db3164ec2a3c3ebc2db57aec8c4cb3231c3dc6cda0c700e1bd',
'signature':'0xf474de893c5a47d9114d2a95f1bd0e4c83b464e8a17886a07ea8d04046949a17dbb8173183c08d4cadbe530c7f42a65fa3286a5f28644a76cf59f6411a04220f'
}
},
{
'type':1,
'reference':0
}
]
},
'blockId':'0x99d29eceb87b44664361f7faf9d8f3b072c6e3e890953fdf956f6d148d9b04b2',
'inclusionState':'Pending',
'timestamp':'1665992931904',
'transactionId':'0xeed7357bf0c0bbdca809e5e537af5a10872e488b26a157af78c68e104420ad75',
'networkId':'1856588631910923207',
'incoming':False,
'note':None
}
]
{
"outputId":"0xd96c9cdf8c6b095f7ab44105f8298c766a7433664db651bfbd7832566d59f1030000",
"metadata":{
"blockId":"0xf56489d9df639ab25e9a72070c4bb5409a8818ccdb5718125538e792f2f27e99",
"transactionId":"0xd96c9cdf8c6b095f7ab44105f8298c766a7433664db651bfbd7832566d59f103",
"outputIndex":0,
"isSpent":false,
"milestoneIndexBooked":1235250,
"milestoneTimestampBooked":1664311584,
"ledgerIndex":1244051
},
"output":{
"type":6,
"amount":"52000",
"nftId":"0x0000000000000000000000000000000000000000000000000000000000000000",
"unlockConditions":[
{
"type":0,
"address":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
],
"features":[
{
"type":2,
"data":"0x5368696d6d65722e20546f6b656e697a652045766572797468696e672e2048656c6c6f2066726f6d20746865204a6176612062696e64696e672e"
}
]
},
"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
]
}
]
}