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
- Rust
- Typescript (Node.js)
- Python
- Instantiate a
Wallet
, get Alice'sAccount
which was created in the first guide and sync it. - Get all the unspent
Outputs
related to theAccount
by calling theAccount.unspent_outputs()
function.
- Prepare and send a
Transaction
to consolidate the Outputs by calling theAccount.consolidate_outputs()
function.
- Await for the
Transaction
to get confirmed by calling theAccount.retry_transaction_until_included()
function.
- Instantiate a
Wallet
, get Alice'sAccount
which was created in the first guide and sync it. - Get all the unspent
Outputs
related to theAccount
by calling theAccount.unspent_outputs()
function.
- Send a
Transaction
to consolidate the Outputs by calling theAccount.consolidateOutputs()
function.
- Await for the
Transaction
to get confirmed by calling theAccount.retryTransactionUntilIncluded
function.
The following example will:
- Instantiate a
Wallet
, get Alice'sAccount
which was created in the first guide and sync it. - Get all the unspent
Outputs
related to theAccount
by calling theAccount.unspent_outputs()
function.
- Prepare a
Transaction
to consolidate the Outputs by calling theAccount.consolidate_outputs()
.
- Await for the
Transaction
to get confirmed by calling theAccount.retry_transaction_until_included
function.
Full Example Code
- Rust
- Typescript (Node.js)
- Python
sdk/examples/how_tos/accounts_and_addresses/consolidate_outputs.rs
loading...
bindings/nodejs/examples/how_tos/accounts_and_addresses/consolidate-outputs.ts
loading...
bindings/python/examples/how_tos/accounts_and_addresses/consolidate_outputs.py
loading...
Expected Output
- Rust
- Typescript (Node.js)
- Python
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([]))
Account synced
Outputs BEFORE consolidation:
OUTPUT #0
- address: rms1qr58umklvtqa4yxxwmskgzyhx2axfe5tfvunu5gauqu9sns7ava3u3kehwq
- amount: 1000000
- native tokens: undefined
OUTPUT #1
- address: rms1qr58umklvtqa4yxxwmskgzyhx2axfe5tfvunu5gauqu9sns7ava3u3kehwq
- amount: 998000000
- native tokens: undefined
OUTPUT #2
- address: rms1qz7652a7c7s9pcur04x7jlmmnyfq8mpxgahmz50tzqutmv6p72vus60pqsd
- amount: 1000000
- native tokens: undefined
Sending consolidation transaction...
Transaction sent: 0x245f75cb1b985304ceb022687e5c70ed6a936d667258015303e3f7f9ec285bbf
Transaction included: https://explorer.shimmer.network/testnet/block/0x5c06b0d2a16e22a54ca2f976a12d56515b58f8310c77de724b8d03dc4f862180
Account synced
Outputs AFTER consolidation:
OUTPUT #0
- address: rms1qr58umklvtqa4yxxwmskgzyhx2axfe5tfvunu5gauqu9sns7ava3u3kehwq
- amount: 1000000000
- native tokens: undefined
Account synced
Outputs BEFORE consolidation:
OUTPUT #0
- address: rms1qr58umklvtqa4yxxwmskgzyhx2axfe5tfvunu5gauqu9sns7ava3u3kehwq
- amount: 1000000
- native tokens: None
OUTPUT #1
- address: rms1qr58umklvtqa4yxxwmskgzyhx2axfe5tfvunu5gauqu9sns7ava3u3kehwq
- amount: 998000000
- native tokens: None
OUTPUT #2
- address: rms1qz7652a7c7s9pcur04x7jlmmnyfq8mpxgahmz50tzqutmv6p72vus60pqsd
- amount: 1000000
- native tokens: None
Sending consolidation transaction...
Transaction sent: 0x245f75cb1b985304ceb022687e5c70ed6a936d667258015303e3f7f9ec285bbf
Transaction included: https://explorer.shimmer.network/testnet/block/0x5c06b0d2a16e22a54ca2f976a12d56515b58f8310c77de724b8d03dc4f862180
Account synced
Outputs AFTER consolidation:
OUTPUT #0
- address: rms1qr58umklvtqa4yxxwmskgzyhx2axfe5tfvunu5gauqu9sns7ava3u3kehwq
- amount: 1000000000
- native tokens: None