Smartcity Hack Substrate Workshop

This is the cheatsheet in addition to my SmartCityHack Workshop

(part1, part2; sorry, videos available in Russian only so far..)


Polkadot Substrate briefly

See A brief summary of everything Substrate and Polkadot.

Runtime vs Smart Contracts

Polkadot parachains require more effort from the developers than smart contract-based Dapps and some applications don’t justify setting up a whole parachain, while others do. This depends on the scope of each application and has to be evaluated on an individual basis


One could argue that parachains are optimized for interoperability (communication between separate applications/chains), while smart contracts are optimized for intraoperability (communication within a chain runtime).



Substrate Runitme Modules library

  • Assets
  • Aura
  • Balances
  • Consensus
  • Contract
  • Council
  • Democracy
  • Finality Tracker
  • Grandpa
  • Indices
  • Session
  • Staking
  • Sudo
  • Timestamp
  • Treasury

Build your chain in 30 minutes

From scratch!

Use template node-template.

Follow the tutorial.

Have a look on Gav’s demo from Web3 Summit 2018.

Robonomics Substrate Node

Robonomics: brief introduction.

Robonomics node built on Substrate.

To start a node, launch command

$ ./target/release/robonomics --bootnodes /ip4/ --name greez --telemetry-url  ws://

Make Polkadot UI understand it: put this json to Settings/Developer/Custom type definitions

Let’s dissect the runtime logic



hint: promisee - тот, кто шлёт Demand (кредитор) promisor - тот, кто шлёт Offer (должник). В текущей версии именно он финализирует обязательство (что не очень правильно, см ниже как добавим Custodian-a)

model - ipfs хеш файла с идентификатором кфс; например, описание пакетов, которые установлены на дроне, их параметров и т.п objective - ipfs хеш файла-таблицы с данными для кфс; например, координата куда должен прилететь дрон, или gcode для 3д принтера result - ipfs хеш файла с протоколом работ или результатом проверки; например, третья сторона проверила конечное местоположение дрона, финализировала контракт, указав подтверждение- файл со своими координатами обнаруженного дрона.

при матчинге Offer-Demand, создаётся обязательство: fn create_liability при этом резервируется сумма контракта на счету promisee:

T::Currency::reserve(&promisee, order.cost)
   .map_err(|_| "promisee's balance too low")?;

которая затем пересылается при финализировании обязательства:

 T::Currency::repatriate_reserved(&liability.promisee, &liability.promisor, liability.order.cost)?;

Try It with UI

If you don’t have your own Node yet, go to, Custom Tab and set this endpoint: wss://

Modify, re-build and launch

Let’s add the Custodian role into the process. Currently, promisor finalizes liability by himself. This allows him to misbehavior and take the money without really executing the order. We need a third party here, let’s call him Custodian, who verifies the order execution and finalizes the liability.

Take a look at my Pull Request: (yay! it’s merged! 😜 )

It’s quite a simple (but powerful!) upgrade: just 7 strings of new code, find them by the prepending commment starting with // ACTION: add custodian here

Checkout this upgraded version, and now build it

$ ./
$ cargo build --release

Why 2 do we need two builds:

Purge chain (not the only possible option):

$ ./target/release/robonomics  purge-chain --dev

Alternative option: don’t purge, just load new wasm runtime runtime/wasm/target/wasm32-unknown-unknown/release/robonomics_runtime.compact.wasm (awesome fork-less feature of Substrate)


$ ./target/release/robonomics --name greez --dev

Update custom types to Polkadot UI at Settings/Developer/Custom type definitions

    "Order": {
        "model": "Vec<u8>",
        "objective": "Vec<u8>",
        "cost": "Balance",
        "custodian": "AccountId"
    "Demand": {
        "order": "Order",
        "sender": "AccountId"
    "Offer": {
        "order": "Order",
        "sender": "AccountId"
    "Liability": {
        "order": "Order",
        "promisee": "AccountId",
        "promisor": "AccountId",
        "result": "Option<Vec<u8>>"
    "LiabilityIndex": "u64"

Some ideas for further improvements

Substrate UI

Home task

Build UI for the Robonomics Liability process Good explanation of how to accomplish this