Skip to content

LedgerSwarm's RLN Smart Contract Framework

TLDR

A smart contract is a state machine

LedgerSwarm smart contracts are permissioned and private state machines that can only be acted upon by those that are party to the contract. LedgerSwarm smart contracts are self contained and operate independely of the RLN protocol by delegating RLN actions to participants' Smart Contract Wallets. This means that they can operate across any ledger type which is running on a LedgerSwarm RLN.

Imag6

The components of a smart contract

Each smart contract contains;

state data - a data object that contains the properties of the contract. For example a loan contract might have an amount, a maturity date and an interest rate. State also contains the 'status' of the contract - for example, a loan might have statuses of 'approved', 'active' or 'matured'.

roles - the roles object connects contract roles to identities. A transition function can only be called by a party with a verified identity and a defined role.

flow constraints - flow constraints determine which roles can operate which transition functions in each defined status of a contract. For example, the status of a loan contract might only be moved from approved to active by the lender by calling the 'approve' transition function. And this can only be done when the status of the contract is 'approved'

transition functions - transition functions are functions that change the state data object by taking the latest state, changing it in some way, and saving a new state. State can only be changed by calling a transition function. Transition functions must be 'pure functions'. Pure functions are functions that always yield consistent output given the same input and do not have any side effects.

schemas - schemas are descriptions of JSON objects. State, roles, flow constraints, and parameters for transition functions are all defined using schemas. Schemas are used to inform participants of the parameters they need to submit to a transition function and to validate any calls to those functions.

Immutable storage

The smart contract object is a collection of hashes, each of which is the key to a content addressable store containing a particular element of the smart contract - including a LedgerSwarm smart contracts are

{
  "stateHash": "de0a493298d63393bc28432d7405a3dfb54a725a4f50c744aa86059264a09e67",
  "transforms": "ffb29ccd52e4b8773a57fe338d2089b795ccd048962ad0d1078a1618f1d109d7",
  "stateFunctions": "3d980f0bedf2fd980fef796d3c9989472cc943e0b2d703c97b8fcaabbeec6ccc",
  "stateData": "6c79e6193bde5afcdbe9c7e93c50a5c9ec25438843f2e2107f0ba8a67cd518c9",
  "stateRoles": "5b501512e112c360dd0af581e08809a3119954b2c3a80ef387a8048b78df0526",
  "priorHash": "ecdeae721d0f970652e8a5575c7537e390fe3e054c2fde739efa0f26b8b85c54"
}

The lifecycle of a smart contract