Skip to main content

Consolidate Outputs

UTXOs can accumulate over time as users perform transactions, resulting in a fragmented UTXO set with many small outputs. Consolidating these outputs allows you to reduce the overall number of UTXOs, which can improve transaction efficiency and reduce storage deposit fees.

Example Code

  1. Instantiate a Wallet, get Alice's Account which was created in the first guide and sync it.
  2. Get all the unspent Outputs related to the Account by calling the Account.unspent_outputs() function.
sdk/examples/how_tos/accounts_and_addresses/consolidate_outputs.rs
loading...
  1. Prepare and send a Transaction to consolidate the Outputs by calling the Account.consolidate_outputs() function.
sdk/examples/how_tos/accounts_and_addresses/consolidate_outputs.rs
loading...
  1. Await for the Transaction to get confirmed by calling the Account.retry_transaction_until_included() function.
sdk/examples/how_tos/accounts_and_addresses/consolidate_outputs.rs
loading...

Full Example Code

sdk/examples/how_tos/accounts_and_addresses/consolidate_outputs.rs
loading...

Expected Output

Account synced
Outputs BEFORE consolidation:
OUTPUT #0
- address: Bech32Address(rms1qr58umklvtqa4yxxwmskgzyhx2axfe5tfvunu5gauqu9sns7ava3u3kehwq)
- amount: 1000000
- native tokens: Some(NativeTokens([]))
OUTPUT #1
- address: Bech32Address(rms1qr58umklvtqa4yxxwmskgzyhx2axfe5tfvunu5gauqu9sns7ava3u3kehwq)
- amount: 998000000
- native tokens: Some(NativeTokens([]))
OUTPUT #2
- address: Bech32Address(rms1qz7652a7c7s9pcur04x7jlmmnyfq8mpxgahmz50tzqutmv6p72vus60pqsd)
- amount: 1000000
- native tokens: Some(NativeTokens([]))
Sending consolidation transaction...
Transaction sent: 0x245f75cb1b985304ceb022687e5c70ed6a936d667258015303e3f7f9ec285bbf
Transaction included: https://explorer.shimmer.network/testnet/block/0x5c06b0d2a16e22a54ca2f976a12d56515b58f8310c77de724b8d03dc4f862180
Account synced
Outputs AFTER consolidation:
OUTPUT #0
- address: Bech32Address(rms1qr58umklvtqa4yxxwmskgzyhx2axfe5tfvunu5gauqu9sns7ava3u3kehwq)
- amount: 1000000000
- native tokens: Some(NativeTokens([]))