Skip to content


Switch branches/tags
This branch is 931 commits ahead of jsnewby:develop.

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time



The middleware is a caching and reporting layer which sits in front of the nodesof the aeternity blockchain. Its purpose is to respond to queries faster than the node can do, and to support queries that for reasons of efficiency the node cannot or will not support itself.

On startup, the middleware reads the entirety of the blockchain, and stores a denormalized version of the data in a PostgreSQL database.

Full documentation is available in the manual.



The middleware answers a set of queries (listed below) on behalf of the node. Everything it doesn't itself answer it will forward to the node to handle. The goal here is to answer more quickly than the node, without sacrificing correctness.


A set of queries will list, for example, all transactions for a given account, all which transfer from one user to another, all between certain block heights, and so on


The middleware unpacks and stores all contract calls for which it has the bytecode, with the function called and the arguments. In the near future we will also store the return type and value. You can see all contract calls for a given contract.

State channels

You can see all active state channels, and for a given state channel, all of the related on-chain transactions


You can see all names registered, and also which names refer to a given address (reverse lookup).


You can see all active oracles. In the near future we will create an endpoint which lists all questions and responses from an oracle


(see below for more information).

The middleware permits you to subscribe to events via a websocket, and receive updates when the chain state changes. Currently you can subscribe to key blocks, micro blocks, and soon to all events involving a particular on-chain object (contract, account, ...).

How to use the middleware

Use ours!

There is a hosted middleware for the æternity mainnet at, and one for the testnet at

Install your own

  • Install a postgresql DB somewhere. Version 11.2 or greater are supported.
  • as the postgresql admin user, execute scripts/prepare-db.sql which will create the DB and user
  • copy 'Rocket.example.toml' to 'Rocket.toml' and edit as you see fit
  • copy .env.example to .env
  • if you want to use a different DB name, edit scripts/prepare-db.sql, .env and Rocket.toml

Run via Docker

This setup runs node, compiler, postgres and aeternal together.

In the examples folder there are 2 setup for docker:

  • examples/docker-compose.yml that includes also the node configuration
  • examples/docker-compose.existing-node.yaml that relies on an existing node

Run docker including the node

  • Install Docker and Docker Compose.
  • Update examples/node/config.yaml as per your requirement.
  • From the project examples folders run docker-compose up

Run docker including relying on an existing node

  • Install Docker and Docker Compose
  • Make sure you can reach the node external port from your machine
  • Edit the file examples/docker-compose.existing-node.yaml and set the url of your node as explained in the file
  • From the project examples folder run docker-compose up -f docker-compose.existing-node.yaml

Tips and tricks

You can run several instances of the middleware simultaneously, with different options. A sensible way of doing this would be one or more using the -s option to serve clients, and one (and only one) with the -p option, populating the database.

If you don't want to interrupt service, want to update the database with new features, and can live with short-term (possible) inconsistencies, use the -H option with the whole chain to force a reload, but serve from the old version soon.

**DON'T USE diesel migration run! **

We now update migrations automatically on application start--and the command diesel migration run overwrites important files.

How to build

You need a nightly rust build

rustup default nightly


cargo build

The middleware will automatically set up its DB on initialization, and run migrations after an update, if they are necessary.

On Ubuntu 18 and 19 the following packages are needed: libpq-dev, libssl-dev and zlib1g-dev. YMMV depending on whether you've e.g. gcc installed.

How to run

Development mode

cargo run -- + flags below

Release mode

cargo build --release # make a release build--this will take a long long time
./target/release/mdw # + flags below


        --help        Prints help information
    -H, --heights     Adds or replaces a set of heights, or ranges of heights separated by
    		      commas to the database. i.e. -H1,3-4,6,100-200
    -d, --daemonize   If set, the middleware will daemonize on startup
    -p, --populate    Populate DB
    -s, --server      Start server
    -v, --verify      Check the DB against the chain
    -V, --version     Prints version information

Environment variables

NODE_URL - the URL of the æternity node AESOPHIA_URL - if present, the middleware will attempt to use this to decode contract calls, storing the function called, and its parameters PID_FILE - if present, and the -d option is set, the middleware stores its pid in this file LOG_DIR - if present, this directory is used for logs, otherwise stdout is used DATABASE_URL - PostgreSQL connection URL STATUS_MAX_BLOCK_AGE

Supported queries

GET /middleware/channels/active
GET /middleware/channels/transactions/address/<address>
GET /middleware/compilers
GET /middleware/contracts/all
GET /middleware/contracts/calls/address/<address>
GET /middleware/contracts/transactions/address/<address>
POST /middleware/contracts/verify
GET /middleware/generations/<from>/<to>?<limit>&<page>
GET /middleware/height/at/<millis_since_epoch>
GET /middleware/names/<name>
GET /middleware/names?<limit>&<page>
GET /middleware/names/active?<limit>&<page>
GET /middleware/names/reverse/<account>?<limit>&<page>
GET /middleware/oracles/list?<limit>&<page>
GET /middleware/oracles/<oracle_id>?<limit>&<page>
GET /middleware/reward/height/<height>
GET /middleware/size/current
GET /middleware/size/height/<height>
GET /middleware/status
GET /middleware/transactions/account/<account>/count
GET /middleware/transactions/account/<sender>/to/<receiver>
GET /middleware/transactions/account/<account>?<limit>&<page>
GET /middleware/transactions/interval/<from>/<to>?<limit>&<page>
GET /middleware/transactions/rate/<from>/<to>

GET /v2/generations/current
GET /v2/generations/height/<height>
GET /v2/key-blocks/current/height
GET /v2/key-blocks/hash/<hash>
GET /v2/key-blocks/height/<height>
GET /v2/micro-blocks/hash/<hash>/header
GET /v2/micro-blocks/hash/<hash>/transactions
GET /v2/micro-blocks/hash/<hash>/transactions/count
GET /v2/transactions/<hash>

Websocket support

The websocket is exposed by default on but can be overridden with the environment variable `WEBSOCKET_ADDRESS`. On our hosted sites it is available as wss:// and wss://, which are the recommended URLs.

Message format:

"op": "<operation to perform>",
"payload": "<message payload>"

Supported ops:

  • subscribe
  • unsubscribe

Supported payload:

  • KeyBlocks
  • MicroBlocks
  • Transactions
  • TxUpdate
  • object, which takes a further field, 'target'--see below

Object subscriptions

You may subscribe to any æternity object type, and be sent all transactions which reference the object. There is an example of this below.

Returned data

Subscriptions return the array of subscriptions (possibly empty):

{"op":"Subscribe", "payload": "KeyBlocks"}
{"op":"Subscribe", "payload": "MicroBlocks"}
{"op":"Unsubscribe", "payload": "MicroBlocks"}
{"op":"Subscribe", "payload": "Object", "target": "ak_2eid5UDLCVxNvqL95p9UtHmHQKbiFQahRfoo839DeQuBo8A3Qc"}
["KeyBlocks","MicroBlocks", "ak_nv5B93FPzRHrGNmMdTDfGdd5xGZvep3MVSpJqzcQmMp59bBCv"]

Actual chain data is wrapped in a JSON structure identifying the subscription to which it relates:


Testing the websocket

Here is some magic you can run in your Javascript console

var exampleSocket = new WebSocket("ws://");
exampleSocket.onopen = function (event) {  // when connection is open, send a subscribe request
    exampleSocket.send('{"op":"Subscribe", "payload": "KeyBlocks"}');
    //to unsubscribe: exampleSocket.send('{"op":"Unsubscribe", "payload": "KeyBlocks"}')

exampleSocket.onmessage = function (event) {
   	console.log(; // you get data here when it arrives


Æterrnal--the caching and reporting layer for the æternity blockchain








No packages published


  • Rust 47.6%
  • Vue 40.4%
  • JavaScript 4.4%
  • PLpgSQL 2.6%
  • TSQL 2.3%
  • Shell 0.9%
  • Other 1.8%