Loading...
Loading...
Midnight RPC interface — JSON-RPC methods for contract state, ZSwap chain state, ledger version, Polkadot SDK defaults, and Partnerchain RPCs. Use when building dApps, wallets, explorers, or configuring node RPC exposure for validators vs observers.
npx skill4agent add kali-decoder/midnight-skills midnight-rpcflowchart 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| Method | Purpose |
|---|---|
| JSON-encoded smart contract state |
| Raw binary-encoded contract state at a block |
| Unclaimed tokens/rewards for a beneficiary |
| ZSwap chain state for a contract |
| Supported RPC API versions (tooling compatibility) |
| Ledger version at a block |
#[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>;atflowchart 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| Method | Purpose |
|---|---|
| Node health status |
| Fetch block by hash |
| Read storage at a key |
| List all supported RPC endpoints |
rpc_methodsNote: 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.
midnight-indexer/Warning: Not all RPC methods are safe to expose on public or production nodes.
| Risk | Mitigation |
|---|---|
| Sensitive data leakage | Use |
| External attack surface | Avoid |
| Performance abuse | Limit 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 --> Auditmidnight-onchain-logic/midnight-indexer/midnight-transactions/