API Reference

let app = Lotion(options)

Create a new Lotion app.

Here are the available options for options which you can override:

  initialState: {},              // initial blockchain state
  keyPath: 'privkey.json',       // path to privkey.json. generates own keys if not specified.
  genesisPath: 'genesis.json',   // path to genesis.json. generates new one if not specified.
  peers: [],                     // array of '<host>:<p2pport>' of initial tendermint nodes to connect to. does automatic peer discovery if not specified.
  logTendermint: false,          // if true, shows all output from the underlying tendermint process
  p2pPort: 26658,                // port to use for tendermint peer connections
  rpcPort: 26657                 // port to use for tendermint rpc

app.use(function(state, transaction, context) { })

Register a transaction handler. Given a state and transaction object, mutate state accordingly.

Transaction handlers will be called for every transaction, in the same order you passed them to app.use().

Transaction handlers must be deterministic: for a given set of state/transaction/context inputs, you must mutate state in the same way.

context is an object like:

  time: 1541415248, // timestamp of the latest block. (unix seconds)
  validators: {
  	// voting power distribution for validators
    '<base64-encoded pubkey>' : 20,
    '<other pubkey>': 147

If you'd like to change how much voting power a validator should have, simply mutate context.validators[pubKey].

app.useBlock(function(state, context) { })

Add middleware to be called once per block, even if there haven't been any transactions. Should mutate state, see above to read more about context.

Most things that you'd use a block handler for can and should be done as transactions.


Starts your app.

Global Chain Identifiers and Light Clients

Lotion apps each have a unique global chain identifier (GCI). You can light client verify any running Lotion app from any computer in the world as long as you know its GCI.

let { connect } = require('lotion')
let GCI = '6c94c1f9d653cf7e124b3ec57ded2589223a96416921199bbf3ef3ca610ffceb'

let { state, send } = await connect(GCI)

let count = await state.count
console.log(count) // 0

let result = await send({ nonce: 0 })

count = await state.count
console.log(count) // 1

Under the hood, the GCI is used to discover and torrent the app's genesis.json.

You can get the GCI of an app being run by a full node like this:

let app = require('lotion')({ initialState: { count: 0 } })

let { GCI } = await app.start()
console.log(GCI) // '6c94c1f9d653cf7e124b3ec57ded2589223a96416921199bbf3ef3ca610ffceb'