github.com/diadata-org/diadata@v1.4.593/documentation/oracle-documentation/polkadot-offchain-worker.md (about) 1 --- 2 description: This page contains an overview over the DIA offchain worker for Polkadot 3 --- 4 5 # Polkadot Offchain Worker 6 7 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. 8 9 ### How it works 10 11 The DIA offchain worker \(ocw\) is a component that can be ported to parachains and is located in [this repository](https://github.com/diadata-org/dia-substrate). 12 13 This offchain worker \(ocw\) gets data from a [DIA API endpoint](../api-1/api-endpoints.md) 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. 14 15 ### Installation 16 17 To add the ocw \(offchain worker\) pallet to your node, add it to your runtime like this \(in this repository already done\): 18 19 1. Edit your [`runtime/Cargo.toml`](https://github.com/diadata-org/dia-substrate/blob/dia/bin/node/runtime/Cargo.toml): 20 * Add this section specifying the ocw path under `[dependencies]`: 21 22 ```text 23 pallet-dia-ocw = { version = "2.0.0", default-features = false, path = "../../../frame/dia-ocw" } 24 ``` 25 26 * Add `"pallet-dia-ocw/std",` at the `[features]`section: 27 28 ```text 29 [features] 30 std = [ 31 [...] 32 "pallet-dia-ocw/std", 33 ] 34 ``` 35 2. Edit [`runtime/src/lib.rs`](https://github.com/diadata-org/dia-substrate/blob/dia/bin/node/runtime/src/lib.rs) like this: 36 * Add the ocw trait: 37 38 ```text 39 impl pallet_dia_ocw::Trait for Runtime { 40 type Event = Event; 41 type Call = Call; 42 type AuthorityId = pallet_dia_ocw::crypto::TestAuthId; 43 } 44 ``` 45 46 * Insert `DIAOCW: pallet_dia_ocw::{Module, Call, Event<T>},` to the `Runtime` enum: 47 48 ```text 49 construct_runtime!( 50 pub enum Runtime where 51 Block = Block, 52 NodeBlock = node_primitives::Block, 53 UncheckedExtrinsic = UncheckedExtrinsic 54 { 55 // ... 56 DIAOCW: pallet_dia_ocw::{Module, Call, Event<T>}, 57 } 58 ); 59 ``` 60 61 ### Usage 62 63 For each block, this offchain worker automatically adds a signed transaction of the [endpoint specified in its source code](https://github.com/diadata-org/dia-substrate/blob/b33de6325e326c299b9c87fafd440ef63efe095b/frame/dia-ocw/src/lib.rs#L133). The signer account needs to be funded appropriately to pay the transaction fees. 64 65 #### Local development mode 66 67 * Start the node and dev network by running `cargo run -- --dev --tmp`. 68 * Create an account or add a subkey to an existing account, e.g. the example account `Alice` via RPC: 69 70 ```text 71 curl http://localhost:9933 -H "Content-Type:application/json;charset=utf-8" -d \ 72 '{ 73 "jsonrpc":"2.0", 74 "id":1, 75 "method":"author_insertKey", 76 "params": [ 77 "dia!", 78 "bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice", 79 "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" 80 ] 81 }' 82 ``` 83 84 The ocw should now write values from the DIA API to the parachain. 85