RGB Blackpaper
GitHubFAQTech talksReddit
  • RGB Blackpaper
  • General information
    • 1. Introduction
      • 1.1. Motivation
      • 1.2. Background
    • 2. Protocol design
      • 2.1. Design goals
      • 2.2. Design overview
  • Consensus layer
    • 3. Client-side-validation
      • 3.1. Proof of publication
      • 3.2. Single-use-seals
      • 3.3. Deterministic bitcoin commitments
        • 3.3.1. Tapret commitments
        • 3.3.2. Opret commitments
        • 3.3.3. Deterministic output selection
      • 3.4. Multi-protocol commitments
    • 4. Ubiquitous deterministic computin
      • 4.1. Strict types system
      • 4.2. AluVM virtual machine
    • 5. Contracts, state & operations
      • 5.1. Schema
      • 5.2. Contract state
      • 5.3. Contract operations
      • 5.4. Contract validation
  • Application layer
    • 6. Writing contracts. Scripting.
    • 7. Interacting with contracts
    • 8. P2P communications
    • 9. Wallet interaction
    • 10. Possible applications
      • 10.1. Bitcoin Finance (BiFi) on Lightning
      • 10.2. Non-financial applications
  • Other information
    • 11. Governance
      • 11.1. Organizations
      • 11.2. Ossification & upgradability
    • 12. Protocol properties
      • 12.1. Privacy
      • 12.2. Censorship-resistance
      • 12.3. Trust model
      • 12.4. Global state & avaliability
      • 12.5. Comparison to other systems
    • 13. History & acknowledgements
  • Appendices
    • References
    • Appendix A: Related standards
    • Appendix B: Reference implementation
    • Appendix C: Glossary
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Application layer

7. Interacting with contracts

But how the wallet makes the sense of the contract? RGB contract can do a lot of things, and if schema developers would need to do a separate wallet for each schema the entrance threshold would be too high. To avoid such situation a concept of contract interface was created. A contract interface is a standard way communicating with RGB Node asking it for a semantically-meaningful state and creating operations. Such concept of interface is similar to the concept of ERC standards and ABI files in Ethereum world; the most common interfaces are called "RGBxx" and are defined as a separate LNP/BP standards.

Here, instead of using existing interface standards we will create an interface for a generic fungible token from scratch to explain the way they work:

interface FungibleToken:
   global Ticker -> String -- this is similar to schema definition; in fact
                           -- it is a requirement that the schema must provide
                           -- a global state of the String type and link it to
                           -- the "Ticker" name
   global Name -> String

   owned Inflation :: Zk64 -- pretty much the same applies to assigned state
   owned Asset :: Zk64

   op Issue :: Inflation -> [Asset]?, Inflation? -- and operations
   op Transfer :: {Asset} -> [Asset]

-- Specific schema state may use different naming, for instance because a
-- schema can define multiple assets with different names; in that case we
-- will have multiple interface implementations referencing different state.
implement FungibleToken for DecentralizedIdentity
   global Ticker := IOYTicker -- this creates a _binding_ of the state defined
                              -- in the schema (*IOYTicker* in this case) to
                              -- the interface
   global Name := IOYName
   owned Inflation := IOYIssue
   owned Asset := IOYTokens
   op Issue := Promise
   op Transfer -- here we skip `:=` part since the interface operation name
               -- matches the name used in the schema. In such cases we can
               -- also skip the declaration at whole

RGB smart contract can implement multiple interfaces. In our case it would be desirable to expose the identity information as well:

interface PgpIdentity
  owned Identity :: PgpKey
  exec Revocation :: old Identity -> new Identity

implement PgpIdentity for DecentralizedIdentity
  -- we do not need to put anything here since schema state and operation
  -- names matches interface requirements and the compiler is able to guess
  -- the bindings
Previous6. Writing contracts. Scripting.Next8. P2P communications

Last updated 2 years ago

Was this helpful?