Back to Browse

Use with your AI agent

  1. Install — run npx skills add Kali-Decoder/Midnight-skills --skill midnight-rpc for this skill, or npx skills add Kali-Decoder/Midnight-skills for all
  2. Prompt — copy the example prompt and paste it into Cursor, Claude Code, or Codex
  3. Build — the agent loads this skill and scaffolds your Midnight work

RPC Interface

FoundationIntermediateReviewedUpdated 12 days agov1.0.0

Learning path

Part of Midnight node architecture · Step 5 of 7

Agent picks this when: Query Midnight node RPC — contract state, ZSwap, and ledger methods

JSON-RPC methods for contract state, ZSwap chain state, ledger version, Polkadot SDK defaults, and Partnerchain RPCs.

Good for

  • Custom midnight_* JSON-RPC methods for contract and ledger state.
  • Polkadot SDK defaults, Partnerchain RPCs, and validator RPC security.

Preview in agent

Suggested prompts

Query Midnight node RPC — contract state, ZSwap, and ledger methods. Use the "midnight-rpc" skill from MIDSKILLS. Follow Compact smart-contract best practices, wire wallet flows where needed, and explain each step as you implement. Target Midnight Preprod unless I specify otherwise.

Loaded skill midnight-rpc

What the skill guides the agent to do:

  1. Custom midnight_* JSON-RPC methods for contract and ledger state.
  2. Polkadot SDK defaults, Partnerchain RPCs, and validator RPC security.

Illustrative — based on the skill's description, not recorded agent output.

Try it without installing: npx skills use Kali-Decoder/Midnight-skills@midnight-rpc

What changed in v1.0.16

All registry changes

No changes in v1.0.16 — last updated in v1.0.12.

On this page · 8 sections
SKILL.md

RPC Interface

The Remote Procedure Call (RPC) layer lets external clients — dApps, wallets, explorers, services — interact with a running Midnight node over HTTP/HTTPS or WebSocket.

Midnight RPCs follow the JSON-RPC standard.

Client ↔ node flow

flowchart LR
  subgraph Clients
    DApp["dApp / wallet"]
    Explorer["Block explorer"]
    Svc["Backend service"]
  end

  subgraph Node["Midnight node"]
    RPC["JSON-RPC layer"]
    RT["Runtime / pallet-midnight"]
    Store["State storage"]
  end

  DApp -->|HTTP / WSS| RPC
  Explorer --> RPC
  Svc --> RPC
  RPC --> RT
  RT --> Store

What RPC enables

  • Submitting transactions (state transitions)
  • Querying on-chain contract state
  • Fetching auxiliary data (off-chain values, metadata)

Core Midnight RPC methods

Custom methods focused on ledger state, contract state, and system information:

MethodPurpose
midnight_jsonContractStateJSON-encoded smart contract state
midnight_contractStateRaw binary-encoded contract state at a block
midnight_unclaimedAmountUnclaimed tokens/rewards for a beneficiary
midnight_zswapChainStateZSwap chain state for a contract
midnight_apiVersionsSupported RPC API versions (tooling compatibility)
midnight_ledgerVersionLedger version at a block

Method signatures (reference)

#[method(name = "midnight_jsonContractState")]
fn get_json_state(
    &self,
    contract_address: String,
    at: Option<BlockHash>,
) -> Result<String, StateRpcError>;

#[method(name = "midnight_contractState")]
fn get_state(
    &self,
    contract_address: String,
    at: Option<BlockHash>,
) -> Result<String, StateRpcError>;

#[method(name = "midnight_unclaimedAmount")]
fn get_unclaimed_amount(
    &self,
    beneficiary: String,
    at: Option<BlockHash>,
) -> Result<u128, StateRpcError>;

#[method(name = "midnight_zswapChainState")]
fn get_zswap_chain_state(
    &self,
    contract_address: String,
    at: Option<BlockHash>,
) -> Result<String, StateRpcError>;

#[method(name = "midnight_apiVersions")]
fn get_supported_api_versions(&self) -> RpcResult<Vec<u32>>;

#[method(name = "midnight_ledgerVersion")]
fn get_ledger_version(&self, at: Option<BlockHash>) -> Result<String, BlockRpcError>;

Most methods accept an optional at block hash; omit for latest block.

flowchart TB
  Q["Client query"] --> M{"Method type"}
  M -->|Contract| CS["midnight_contractState / jsonContractState"]
  M -->|ZSwap| ZS["midnight_zswapChainState"]
  M -->|Rewards| UA["midnight_unclaimedAmount"]
  M -->|Meta| LV["midnight_ledgerVersion / apiVersions"]
  CS --> Block["Resolve at block hash or latest"]
  ZS --> Block
  UA --> Block
  LV --> Block

Polkadot SDK RPC support

Midnight also exposes default Polkadot SDK methods, including:

MethodPurpose
system_healthNode health status
chain_getBlockFetch block by hash
state_getStorageRead storage at a key
rpc_methodsList all supported RPC endpoints

Call rpc_methods at any time for the full method list on your node.

Note: Some Midnight RPC methods may not appear in Polkadot JS Apps. See Polkadot SDK RPC docs for overlap; support varies by node version and configuration.

For application-level reads, many dApps prefer the Indexer GraphQL API — see indexer/.


Partnerchain RPCs

Midnight exposes Partnerchain-specific RPC methods for block producers and sidechain integration:

  • Query consensus signals
  • Relay finality information
  • Coordinate cross-chain operations

Security: block producers

Warning: Not all RPC methods are safe to expose on public or production nodes.

If you run a block-producing node:

RiskMitigation
Sensitive data leakageUse --rpc-methods Safe
External attack surfaceAvoid --rpc-external unless required
Performance abuseLimit exposed endpoints to your operational role
flowchart TD
  Role{"Node role?"}
  Role -->|Validator / block producer| Safe["--rpc-methods Safe<br/>No --rpc-external"]
  Role -->|Observer / archive| Review["Review threat model<br/>May expose read-only RPC"]
  Safe --> Audit["Audit rpc_methods list"]
  Review --> Audit

Align RPC configuration with your threat model and role (validator vs observer).


  • midnight-onchain-logic/ — what state RPC methods read
  • indexer/ — GraphQL alternative for dApp data
  • midnight-transactions/ — submitting proof-based transactions via RPC

Start in 2 steps

  1. 1. Install — one skill or the full set
  2. 2. Prompt — paste the example into your agent

Install all skills (recommended)

npx skills add Kali-Decoder/Midnight-skills

One command adds every Midnight skill to Cursor, Claude Code, and similar agents.

Install this skill only

npx skills add Kali-Decoder/Midnight-skills --skill midnight-rpc

Installs only "midnight-rpc" into every detected agent (Cursor, Claude Code, Codex, …).

Example agent prompt

Query Midnight node RPC — contract state, ZSwap, and ledger methods. Use the "midnight-rpc" skill from MIDSKILLS. Follow Compact smart-contract best practices, wire wallet flows where needed, and explain each step as you implement. Target Midnight Preprod unless I specify otherwise.

Paste into Cursor, Claude Code, or Codex after installing.

Author
Kali-Decoder
Category
Foundation
Difficulty
intermediate
Version
v1.0.0

Tags

RPCJSON-RPCNodeAPI

Files included

SKILL.md
Create Social CardLive HackathonsGallery
Mock Demo
RPC Interface