- December 28, 2018
- Posted by: iygmg
- Category: Blockchain, Programming Model, Smart Contract
Incentum Smart Contracts use a simple, elegant, and powerful programming model. All objects in Incentum are represented as JSON documents, and the JSONata query and transformation language (restricted, see below) is used for data transformations. First, some terms:
- Ledgers are key pairs and represent accounts.
- Templates are a set of Reducers, which are named bits of JSONata code that execute the contract logic.
- Tokens in Incentum are very abstract and general, and can represent any asset or any tangible or intangible thing. Tokens are created by Contracts, and have a symbol, a globally unique contract identifier, and an amount.
- Contracts are running instances of Templates.
- The State is a JSON object containing the current state of the Contract, and the current Coins and/or Tokens available in the Contract.
- The available Coins/Tokens and data in a Ledger that are available for consumption are represented as Outputs. Basically, Outputs are the generalized equivalent of Bitcoin UTXO’s.
- Minted Tokens are new Coins/Tokens minted by the Contract.
- Inputs are signed Outputs.
- Actions are Inputs and a Reducer name.
There are a few key concepts to understand in order to write contracts with the Incentum effectively.
A Contract is started by instantiating a Template. Actions are then sent to the Contract to execute the contract logic. When an Action is executed, the Reducer is passed the Action, the Inputs, the current State, and the current Coins in the Contract. It produces zero or more Outputs, zero or more Minted Outputs, and a new State.
It’s that simple.
This leads to a very modular programming style, and makes the contract logic very understandable.
Perhaps the most important concept in the Rekoner is how to use Outputs correctly. Outputs in a Ledger are anything that is available for consumption by the owner of the Output. In other words, they can be signed by the Ledger and used as Inputs to Actions on contracts. An Output usually contains Coins, but this is not required. This is a key point. Outputs are used as the communication mechanism for Contract developers. If your Contract logic requires some signed data or Coins from a Ledger in order to continue, just create an Output on that Ledger asking for the appropriate data. Each Ledger can easily see its list of available Outputs, so the Ledger can act on any that need processing.
Each Output and the Contract State can contain any number of different Tokens or Coins. As stated above, Tokens are an abstract representation of any asset or thing. They can be used as normal Tokens, or to tokenize or monetize any asset. Once something is converted to an Incentum Token, it can be used in a Contract.
Tokens are ‘minted’ by Contracts. One of the possible outputs from an Action are called Minted Tokens. They have their origin and identity derived from the running Contract.
Tokens are input and output from Contracts. The Contract checks that the input amount for each Token is greater than or equal to the Outputs for the life of the Contract. If this invariant is not satisfied, the Action will fail.
Note on JSONata
The JSONata language subset allowed is restricted to be deterministic.