Skip to main content

Build Reactive Smart Contracts

info

This section does not dive too much into detail of how smart contracts work theoretically, but is intended to give a high level overview of how to work with smart contracts practically. Smart contracts are fundamentally located inside Coinweb's computation system and are deeper described in this section.

Generally speaking a Coinweb node receives information from any connected L1 blockchain (Bitcoin, Ethereum, etc.) which is piped through Coinweb's shard pipeline to a shuffler. The shuffler is the pipeline component where L2 blocks are generated. L2 blocks consist of a list of transactions which are ultimately going to be processed by the L2 computer. Whenever a block has been forwarded to the L2 computer it examines the included transactions for usable operations.

Processable Operations in L2 Blocks

Below is a table of possible operations the L2 computer can identify and process.

note

For the current version of Coinweb, Transactions are marked with v0 (version 0).

OperationDescription
DataData passed alongside a chain of transactions, commonly used as input for smart contracts.
ReadDatabase lookups/reads.
BlockBlock a transaction given a condition.
TakeRemove a claim from the database owned by the transaction issuer, and add the claim to the transaction. It also adds the CWEB stored in the claim to the transaction, thus it can be spent/passed on to other transactions or stored in other claims. If the claim doesn't exist the transaction fails.
StoreStore a claim into the database owned by the transaction issuer. It can also store CWEB available to the current transaction (similar to an UTXOs in Bitcoin).
CallInvoke a smart contract.

Common Workflow for a Smart Contract

The typical workflow for creating and interacting with smart contracts involves the following steps:

  1. Registration
  2. Utilisation
    • Invocation of a smart contract. Calling a contract is also described in the upcoming chapters.
    • A smart contract can be reused to become part of a composition of smart contracts
    • A smart contract in Coinweb can live forever by invoking itself repeatedly or using the Block operation
    • A smart contract can be set up to execute once
    • It can monitor chain events and execute for a particular event
    • It can monitor chain events and execute for a particular event multiple times until the stored CWEBs are exhausted
    • It can monitor chain events without ever executing
  3. Deregistration
    • The final removing/cancellation step of the smart contract

The upcoming chapters will introduce a practical approach to work with smart contracts