Search code examples
rpcsubstrate

How to extract data from Offchain storage?


I'm trying to access data that I'm storing through the RPC off-chain endpoint. enter image description here I've used OffchainStorage::get() with default config but not getting any data back.

Is there anything do I need to set up explicitly to extract the stored data?


Solution

  • On the client-side we can get the off-chain storage instance from shared backend instance (which is of type Arc < FullBanckend >). This instance can be find inside new_full().

    After getting the Bankend's shared instance, we can access our off-chain storage like this:

    // The relevant ocw storage instance.
    let ocw_storage = backend.offchain_storage();
    
    // Prefix for accessing values for our application.
    let prefix = &sp_offchain::STORAGE_PREFIX;
    
    // Get our value
    ocw_storage.get(prefix, key);