Skip to content

Technical Implementation of RGB Asset Batch Distribution ​

In the ecosystem construction of the RGB protocol, how to efficiently and cost-effectively perform large-scale asset distribution has always been one of the core challenges. Recently, the Stash Labs team successfully implemented the Batch Distribution feature on RGB Dex based on the latest version of the RGB protocol. This technology allows the distribution of RGB assets to hundreds or more wallet addresses simultaneously in a single Bitcoin transaction, significantly improving distribution efficiency and reducing on-chain costs. Video Demo Reference: Watch the full functional demo on X

This article will analyze the operational flow and core principles of this feature from a technical implementation perspective.

Core Technology: Invoice Aggregation Distribution Based on Rust ​

The efficiency of batch distribution is primarily due to the backend implementation of the Rust Batch Transfer System. The system achieves this by aggregating user invoices and constructing a single RGB transfer transaction.

Automated Invoice Generation ​

When a user triggers CLAIM TOKENS on the frontend, the system calls a backend interface to automatically generate RGB invoice details for the corresponding asset. This process ensures that the invoice format for each claim address complies with protocol specifications.

Batch Task Aggregation and Merkle Commitments ​

The core of batch distribution efficiency lies in the aggregated processing of multiple State Transitions:

  1. Scanning the Claim Queue: Continuously retrieve submitted and pending user invoices.
  2. Constructing Aggregated State Transitions: Based on the Client-side Validation model of the RGB protocol, the system merges multiple independent state transition requests. Using Merkle tree technology, these requests are aggregated into a tiny cryptographic Commitment.
  3. Single-Transaction Anchoring: Through the Anchor structure, the aggregated Merkle root is anchored to the output of a single Bitcoin transaction (usually using Tapret or OpRet schemes). This design ensures that hundreds of independent distribution requests appear as a single unified commitment on-chain, greatly compressing the on-chain footprint.
  4. Generating Batch Invoices and Consignments: Generate corresponding Consignments for each address and transmit them offline through P2P networks or data layers (such as Storm).

On-chain Broadcasting and Status Updates ​

The system finally packs the aggregated transaction and broadcasts it to the Bitcoin network. Due to the use of Merkle aggregation technology, a single transaction can theoretically support a very high number of concurrent distributions. Currently, RGB Dex has set a stable upper limit of hundreds or more accounts.


Technical Verification: TXID Consistency Analysis ​

To ensure the on-chain authenticity and atomicity of batch distribution, the Stash Labs R&D team verified the Transaction ID (TXID) via a block explorer.

In actual testing, RGB asset transaction details received by different claim accounts show that their corresponding Bitcoin transaction TXIDs are exactly the same. This proves from the bottom layer that:

  • Resource Optimization: The distribution to hundreds of addresses occupies only the conversion space of a single UTXO set.
  • Protocol Compatibility: It perfectly adapts to the RGB protocol's concurrent processing requirements for Single-use Seals.
  • High-Performance Performance: The RGB protocol demonstrates excellent scalability when handling large-scale concurrent claims.

4. Open Source Reference Implementation: Batch Invoice Demo ​

To help developers better understand and integrate batch distribution technology, we have released an open-source reference implementation project: batch_invoice_demo.

The project provides a multi-language (Python and Rust) reference implementation, demonstrating how to sign and submit batch payment requests for Bitcoin/RGB invoices.

4.1 Core Features ​

  • Batch Payment Signing: Supports secure signing of batch payment requests using Extended Private Keys (XPRV).
  • Private Key Derivation Tool: Provides a practical utility for deriving XPRV keys from BIP39 mnemonics.
  • Multi-network Support: Compatible with Mainnet, Testnet, and Regtest environments.
  • Dual Language Versions: Optimized separately for the Python ecosystem (rapid prototyping) and the Rust ecosystem (high-performance production environments).

4.2 Signature Process Brief ​

The demo code showcases a standard signature workflow:

  1. Message Generation: Construct a normalized JSON message based on request parameters.
  2. Hashing: Use SHA256 to calculate the message hash.
  3. Key Derivation: Extract the derivation path from the descriptor and derive the child private key from the root XPRV.
  4. Signing and Encoding: Use the secp256k1 algorithm for ECDSA signing and output it in hexadecimal format.

Through this open-source demo, developers can quickly get started with the batch processing logic of RGB assets and integrate it into their own wallets or platforms.


5. Conclusion and Future Outlook ​

The batch distribution feature implemented by the Stash Labs team on RGB Dex is a significant step for the RGB protocol towards large-scale commercial use. Through the combination of efficient Rust scripts and platform automation logic, we have not only solved the cost challenge of small-value, high-frequency distribution but also laid the foundation for more complex asset airdrop solutions in the future.

Special thanks to the Bitlight team and the community for their support of Stash Labs. We will continue to delve into RGB storage and distribution infrastructure to optimize the user experience.


Trade and secure your RGB assets | Unlock the full potential of the RGB protocol