There are many docs/tutorials explaining how to extend the node's RPC service with a Custom RPC to query the Runtime storage. What I could not figure it out yet, is how to do the same but to query the Offchain-storage. I basically want to replicate the following available built-in service but with my own Custom RPC: https://paritytech.github.io/substrate/master/sc_rpc_api/offchain/index.html

Below are my snippets:

This example works properly. No storage required.

// node/src/rpc.rs
// Ref: https://substrate.recipes/custom-rpc.html

let mut io = jsonrpc_core::IoHandler::default();

// Add a silly RPC that returns constant values
io.extend_with(SillyRpc::to_delegate(Silly {},));

The following example is the one I'm interested in, and I could not figure it out how to make it work so far. Below I'm trying to incorporate the offchain-storage.

// node/src/rpc.rs
// Ref: https://core.tetcoin.org/rustdocs/v2.0.1/src/sc_rpc/offchain/mod.rs.html

let mut io = jsonrpc_core::IoHandler::default();

let storage = ???????

The closest code I found similar to what I need is the following from builder.rs:

let maybe_offchain_rpc = offchain_storage.map(|storage| {
    let offchain = sc_rpc::offchain::Offchain::new(storage, deny_unsafe);

Also related to the previous question: Is it possible to query an OCW's Off-chain storage via RPC from an external service?

Regards, Pablo.

  • FYI that existing rustdoc link I updated to paritytech.github.io/substrate/master/sc_rpc_api/offchain/… - there is a different API exposed than before, please do check there for the new stuff, and update your question as needed?
    – Nuke
    Aug 15, 2022 at 22:53
  • Also all https://core.tetcoin.org/ links are unmaintained by a 3rd party that should not be referenced.
    – Nuke
    Aug 15, 2022 at 22:54
  • Closing this question because it is stale. If you have a similar question, please open an new post, which will get eyes on it again.
    – Shawn Tabrizi
    Oct 20, 2022 at 20:27
  • I’m voting to close this question because it is stale.
    – Shawn Tabrizi
    Oct 20, 2022 at 20:27


Browse other questions tagged or ask your own question.