- RGB and LNP/BP is a smart contract platform that is scalable, private, and interoperable with Bitcoin and Lightning Network. It is possible to issue assets, create NFTs, and run DAOs on RGB.
- https://twitter.com/Sharp_On_Sats/status/1779818457476825594
https://twitter.com/Sharp_On_Sats/status/1779818457476825594
RGB Protocol Technical Overview
Introduction
- The RGB protocol stands as a cornerstone for building and managing smart contracts on blockchain networks, emphasizing privacy, security, and flexibility. This document delves into the intricate mechanics of RGB, covering state validation, contract schemas, and interfaces, alongside practical code examples.
State Validation
- RGB employs a dual-layer validation process to ensure the integrity and compliance of contract states:

Declarative Rules
- Purpose: Specify the fundamental requirements for state types, ensuring compatibility and correctness.
- Mechanism: If a state, realized as a binary string, does not conform to its expected type upon deserialization, the contract fails validation.
- Example: A rule might dictate that the global state of an asset’s name cannot accumulate more than one item, preserving uniqueness.
Custom Script Logic
- Purpose: Allows for complex state validations beyond the scope of declarative rules.
- Mechanism: Utilizes a virtual machine to inspect and enforce contract-specific conditions, such as verifying transaction IDs within operations.
- Example: Ensuring the sum of input assets equals the sum of output assets in a transaction, maintaining balance integrity.
Contract Schemas
- A schema in RGB defines the structure and rules for a specific type of contract, acting as a blueprint for creating and managing contract instances.
Definition
- Components: Includes state types, data types for constructing states, permissible operations, and their effects on state.
- Importance: Separates contract developers from issuers, allowing issuers to create assets based on predefined templates without deep technical knowledge.
Implementation
- Rust Example: Contracts are typically defined using Rust, providing a robust framework for schema creation.
struct ContractSchema {
global_types: Map<TypeIdentifier, TypeName>,
own_types: Map<TypeIdentifier, TypeName>,
// Additional fields defining operations and their structure...
}
```
- **Simplification**: Future iterations aim to simplify schema creation, making it more accessible to non-developers.
## Interfaces
- Interfaces play a crucial role in making smart contracts accessible and interactable, serving as a bridge between the contract logic and external applications, such as wallets.
### Role and Functionality
- **Definition**: An interface provides a standardized set of operations and state information, making contracts understandable to external software.
- **Examples**: `RGB20` for fungible assets, `RGB21` for NFTs, each defining operations like transfer, issue, or burn.
### Implementation and Binding
- **Process**: Contract schemas implement specific interfaces, mapping state types and operations to the interface's requirements.
```rust
impl Interface for MyContractSchema {
// Mapping schema types to interface definitions...
}
```
## Practical Considerations
### Code Snippets
- Rust is predominantly used for defining schemas and interfaces within the RGB ecosystem. The following snippet outlines a basic schema definition:
- This schema defines two states: one for the asset's name as a global state and another for its precision as an own state.
```rust
const ASSET_NAME: GlobalState = 1;
const ASSET_PRECISION: OwnState = 2;
- let schema = ContractSchema {
global_types: Map::new()
.insert(ASSET_NAME, "String"),
own_types: Map::new()
.insert(ASSET_PRECISION, "u8"),
// Additional schema setup...
};Challenges
- Complexity: The dual-layer validation and the depth of schema definitions can be daunting for new developers.
- Flexibility vs. Standardization: Balancing the need for flexible contract logic with the benefits of standardized interfaces and operations.
Opportunities
- Advancements in Interface Design: Streamlining interface creation to encourage broader adoption and more innovative contract designs.
- Educational Resources: Developing comprehensive guides and tools to lower the entry barrier for new RGB developers.
Conclusion
- The RGB protocol offers a sophisticated framework for creating and managing smart contracts, with a focus on security, privacy, and interoperability. Through its dual-layer validation, detailed contract schemas, and user-friendly interfaces, RGB is poised to facilitate a new era of smart contract development on blockchain networks.
Standards
- Terms and standards explained clearly on the RGB legal page RGB glossary, part I · RGB-WG · Discussion #52 (github.com)
- [e17 The Bitcoin Contracting Layer
- RGB with Maxim Orlovsky by Down The Rabbit Hole With Kaz (spotify.com)](https://podcasters.spotify.com/pod/show/dtrhole/episodes/e17-The-Bitcoin-Contracting-Layer---RGB-with-Maxim-Orlovsky-eqdfh6)
- Samara Asset Group (samara-ag.com)

Links
- RGB FAQ
- Frequently asked questions about the RGB protocol
- RGB Tech
- Technical information and resources for the RGB protocol
- RGB Blackpaper
- Comprehensive technical document describing the RGB protocol
- RGB Spec
- Specifications for the RGB protocol
- LNP/BP Standards
- List of specifications for the LNP/BP protocol suite
- AluVM
- Information about the AluVM virtual machine for smart contracts
- Strict Types
- Documentation for the Strict Types programming language
- Contractum
- Resources related to smart contracts on the RGB protocol
- RGB Working Group GitHub
- GitHub organization for the RGB protocol working group
- RGB Protocol Subreddit
- Subreddit for discussions about the RGB protocol
- RGB Protocol Twitter Community
- Twitter community for the RGB protocol
- LNP/BP Twitter
- Official Twitter account for the LNP/BP project
- RGB Telegram
- Telegram channel for the RGB protocol
- LNP/BP Telegram
- Telegram channel for the LNP/BP project
- RGB Developer Calls
- Information about developer calls for the RGB protocol
- LNP/BP Developer Calls GitHub
- GitHub repository for LNP/BP developer calls
- LNP/BP Developer Calls Wiki
- Wiki for LNP/BP developer calls
- LNP/BP YouTube Channel
- Official YouTube channel for the LNP/BP project
- LNP/BP Presentation Slides
- Repository containing presentation slides for the LNP/BP project
- LNP/BP GitHub
- Main GitHub organization for the LNP/BP project
- BP Working Group GitHub
- GitHub organization for the BP (Bitcoin Protocol) working group
- LNP Working Group GitHub
- GitHub organization for the LNP (Lightning Network Protocol) working group
- Storm Working Group GitHub
- GitHub organization for the Storm working group, focused on Layer 3 protocols and applications
- Hexa wallet https://play.google.com/store/apps/details?id=io.hexawallet.hexa2
- Bitlight wallet
- Bitmask
- DIBA
- Pandora
- Also there is at least two DEXes (one is Kaleidoswap which was demoed last week on Tuscany Lightning Summit), two asset marketplaces, explorer and stablecoin
- everything required to bootstrap the ecosystem