Skip to main content

The explanation on this page assumes you have a certain level of understanding of blockchain technology.

Related information
  • Smart Contracts are invoked by a Call operation during execution of a transaction in the Coinweb Virtual Machine.
  • Smart Contracts are executed in smart contract virtual machines where Web Assembly(WASM) is the only currently implemented smart contract VM.
  • Javascript smart contracts are implemented inside the WASM VM using an interpreter.
  • Decentralized applications and javascript smart contracts are developed in contract-modules which contain both on-chain and off-chain javascript code as described in working with contract-modules.

Introduction to Reactive Smart Contracts

Coinwebs reactive smart contracts () are unique in several different ways to other smart contracts. They open up for the implementation of many new use cases as well as extending existing dApps. Main differences between Coinwebs reactive smart contracts and regular smart contracts:

  • Coinweb Reactive smart contracts can continue to run indefinitely, while regular smart contracts are one-off executions within a single block.
  • Coinweb Reactive smart contracts can self-initiate, while regular smart contracts can only be started by user-initiated transactions in the same block.
  • Coinweb Reactive smart contracts are blockchain agnostic and have access to L1 and L2 data across all connected chains, regular smart contracts can only run on a single chain, and can not see data on other chains.
  • Coinweb reactive smart contracts use CWEB on all chains, regular smart contracts require different gas tokens for each blockchain.
  • Coinweb reactive smart contracts can keep their own gas balance, regular smart contracts can not hold gas balance.
  • Coinweb reactive smart contracts can execute over multiple blockchains, regular smart contracts can only run on one chain.

From the list above, we can see that reactive smart contracts are very powerful compared to ordinary smart contracts. A reasonable comparison would be how early computers could only run one-off programs, while computers today run many programs in the background that solve tasks without the need for user interaction. Computers would be far less useful without the ability to run these background processes.

A very significant advantage is that blockchain-agnostic reactive smart contracts can access and combine L1 data from all connected chains. This means that Coinweb dApps have access to vastly more data than any other dApps. Combined with consistent cross-chain operations, this is what we call unifying interoperability. You can find a deep-dive into how this affects the value potential of dApps here.

How do the Reactive Smart Contracts work?

The principle behind reactive smart contracts is quite simple. Like all Coinweb smart contracts, reactive smart contracts can initiate new transactions. To stay active, the reactive smart contract simply sends a transaction to itself in every block. It can continue to do this as long as it has gas balance. The fee to execute enough to keep active is quite small, so there is no reason that these contracts can run for very long periods at a time. A typical setup would be to check some parameters for each block. Examples of this could be:

  • Monitoring some addresses for incoming payments
  • Monitoring gas fees on different chains
  • Monitoring bridges to detect bridge hacks
  • Monitoring soft staking of assets
  • Checking that agreed transactions have been performed
  • etc

If the smart contract detects an activity that it is monitoring, it will run specific parts of the contract depending on the use case. It could for example be to switch default blockchain for a dApp if the gas fees become too high, or it could be to slash a collateral if a promised transaction is not performed. Or allow redemption of valid wrapped L1 tokens if a bridge has been hacked. Importantly, all of this is under the consensus of the L1 chains. No external information is injected into the process. This means that the outcome follows L1 consensus without the weaker security of external validators or oracles. This functionality allows a new level of decentralised automation previously not possible to achieve.

You can read more about Coinwebs computation framework here.