offchain_localStorageSet - Midnight

Example code for the offchain_localStorageSet JSON-RPC method. Complete guide on how to use offchain_localStorageSet JSON-RPC in GetBlock Web3 documentation.

This method writes a value to the node's off-chain worker local storage. Note that managed RPC providers typically disable this method, since it can affect node behavior.

Parameters

Parameter
Type
Required
Description

kind

string

Yes

Storage kind: PERSISTENT or LOCAL

key

string

Yes

Hex-encoded storage key

value

string

Yes

Hex-encoded value to store

Request Example

curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "offchain_localStorageSet",
    "params": [
        "PERSISTENT",
        "0x6d795f6b6579",
        "0x68656c6c6f"
    ],
    "id": "getblock.io"
}'

Response Example

Response Parameters

Field
Type
Description

result

null

Always null on success

Use Cases

  • Seeding off-chain worker state during local development

  • Test harnesses that need to pre-populate off-chain storage

Error Handling

Status Code
Error Message
Cause

404

Not found

Missing or invalid <ACCESS-TOKEN>

-32602

Invalid params

Request parameters are missing or malformed

-32601

Method not found

RPC call is unsafe to be called externally

429

Too Many Requests

Rate limit exceeded for your plan

SDK Integration

Last updated

Was this helpful?