D
D
DIA Documentation
Search…
Polkadot Offchain Worker
This page contains an overview over the DIA offchain worker for Polkadot
DIA offers a flexible oracle solution for Polkadot. Our offchain worker can be instantiated by any node operator. You can integrate it into your parachain and access the DIA API using the offchain worker.

How it works

The DIA offchain worker (ocw) is a component that can be ported to parachains and is located in this repository.
This offchain worker (ocw) gets data from a DIA API endpoint and writes an event as signed transaction for all local keys with subkey type dia!. It can be used to retrieve any data from the DIA API. The offchain worker "lives" in a node deployed to a parachain and needs an active Internet connection. It acts as an oracle that provides data for any application inside the specific parachain.

Installation

To add the ocw (offchain worker) pallet to your node, add it to your runtime like this (in this repository already done):
    1.
      Add this section specifying the ocw path under [dependencies]:
      1
      pallet-dia-ocw = { version = "2.0.0", default-features = false, path = "../../../frame/dia-ocw" }
      Copied!
      Add "pallet-dia-ocw/std", at the [features]section:
      1
      [features]
      2
      std = [
      3
      [...]
      4
      "pallet-dia-ocw/std",
      5
      ]
      Copied!
    2.
    Edit runtime/src/lib.rs like this:
      Add the ocw trait:
      1
      impl pallet_dia_ocw::Trait for Runtime {
      2
      type Event = Event;
      3
      type Call = Call;
      4
      type AuthorityId = pallet_dia_ocw::crypto::TestAuthId;
      5
      }
      Copied!
      Insert DIAOCW: pallet_dia_ocw::{Module, Call, Event<T>}, to the Runtime enum:
      1
      construct_runtime!(
      2
      pub enum Runtime where
      3
      Block = Block,
      4
      NodeBlock = node_primitives::Block,
      5
      UncheckedExtrinsic = UncheckedExtrinsic
      6
      {
      7
      // ...
      8
      DIAOCW: pallet_dia_ocw::{Module, Call, Event<T>},
      9
      }
      10
      );
      Copied!

Usage

For each block, this offchain worker automatically adds a signed transaction of the endpoint specified in its source code. The signer account needs to be funded appropriately to pay the transaction fees.

Local development mode

    Start the node and dev network by running cargo run -- --dev --tmp.
    Create an account or add a subkey to an existing account, e.g. the example account Alice via RPC:
    1
    curl http://localhost:9933 -H "Content-Type:application/json;charset=utf-8" -d \
    2
    '{
    3
    "jsonrpc":"2.0",
    4
    "id":1,
    5
    "method":"author_insertKey",
    6
    "params": [
    7
    "dia!",
    8
    "bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice",
    9
    "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"
    10
    ]
    11
    }'
    Copied!
The ocw should now write values from the DIA API to the parachain.
Last modified 6mo ago
Export as PDF
Copy link