agentleFS
Kali-DecoderKali-Decoder/Midnight-Skills/.agents/skills/ankr-midnight/SKILL.md

ankr-midnight

Skill18 starsChanged 18 days agoMITView on GitHub

Integrate Ankr as a Midnight Network RPC provider for testnet and mainnet. Covers creating an Ankr project, copying HTTPS/WSS endpoints with API key, wiring the node URL into midnight-js / multinetwork configs, and calling Midnight JSON-RPC methods (midnight_*, system_*, chain_*, state_*). Use when the user asks about Ankr + Midnight, Ankr.js for Midnight, Ankr RPC endpoint, or replacing public Midnight RPC with Ankr.

  • Reads credentials
  • Sends data out

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use Ankr Chain RPC as your Midnight node endpoint for testnet and mainnet.

    line 15
  2. Distinctive:

    Midnight is not in the Advanced API chain list: Do not use:

    line 31
  3. Very specific:

    Call Midnight JSON-RPC methods (midnight_*, system_*, chain_*, …)

    line 57
  4. Distinctive:

    Keep Indexer GraphQL separate (Ankr RPC ≠ Midnight Indexer)

    line 58
  5. Distinctive:

    Create or open a Project (Projects pane)

    line 68

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Ankr + Midnight Network RPC

Use Ankr Chain RPC as your Midnight node endpoint for testnet and mainnet.

What this skill produces: working Ankr HTTPS/WSS URLs with API key, a small JSON-RPC client, midnight-js network config wired to Ankr, and call patterns for Midnight operations.

Primary references:


Critical: Midnight ≠ Ankr.js Advanced API

@ankr.com/ankr.js (AnkrProvider) talks to Ankr Advanced API (ankr_getNFTsByOwner, getAccountBalance, …). Those methods are for EVM chains only (eth, polygon, bsc, …).

Midnight is not in the Advanced API chain list. Do not use:

// ❌ Wrong for Midnight — Advanced API / EVM only
import { AnkrProvider } from '@ankr.com/ankr.js';
const provider = new AnkrProvider('YOUR_ADVANCED_API_ENDPOINT');
await provider.getNFTsByOwner({ blockchain: 'eth', walletAddress: '0x…' });

For Midnight, use Ankr Node / Chain RPC: plain JSON-RPC POST to:

https://rpc.ankr.com/midnight_testnet/<API_KEY>
https://rpc.ankr.com/midnight_mainnet/<API_KEY>

Auth is the API key in the URL path — no Authorization header.


Workflow

  1. Sign in to Ankr RPC and create/select a project
  2. Enable Midnight and copy HTTPS (and optionally WSS) endpoints
  3. Store the full URL (with key) in env — never commit the key
  4. Point midnight-js node / rpc at the Ankr URL
  5. Call Midnight JSON-RPC methods (midnight_*, system_*, chain_*, …)
  6. Keep Indexer GraphQL separate (Ankr RPC ≠ Midnight Indexer)

1) Get your Ankr API key and Midnight endpoints

Sign in

  1. Open https://www.ankr.com/rpc/
  2. Sign in (Google, Ethereum wallet, GitHub, X, etc.)
  3. Create or open a Project (Projects pane)

Premium / paid plans unlock higher rate limits and private endpoints. Free/demo access may be rate-limited — prefer a project key for apps.

Copy Midnight endpoints

  1. In the project, open Chains
  2. Select Midnight
  3. Choose network:
    • Testnet → midnight_testnet
    • Mainnet → midnight_mainnet
  4. Copy HTTPS (required) and WSS (optional, for subscriptions / some SDKs)

URL shape

HTTPS: https://rpc.ankr.com/<network>/<API_KEY>
WSS:   wss://rpc.ankr.com/<network>/<API_KEY>
Midnight networkAnkr pathExample HTTPS
Testnetmidnight_testnethttps://rpc.ankr.com/midnight_testnet/<API_KEY>
Mainnetmidnight_mainnethttps://rpc.ankr.com/midnight_mainnet/<API_KEY>

Formula: Endpoint = Project (API key) + Network.

Official Ankr request examples use a trailing slash:

https://rpc.ankr.com/midnight_testnet/YOUR_ANKR_API_KEY/

Both with and without trailing slash usually work; keep one style consistently.

Env vars (recommended)

# .env.local — never commit
ANKR_API_KEY=your_project_api_key_here

# Or store the full endpoint
ANKR_MIDNIGHT_TESTNET_RPC=https://rpc.ankr.com/midnight_testnet/your_project_api_key_here
ANKR_MIDNIGHT_MAINNET_RPC=https://rpc.ankr.com/midnight_mainnet/your_project_api_key_here

# Optional WebSocket
ANKR_MIDNIGHT_TESTNET_WSS=wss://rpc.ankr.com/midnight_testnet/your_project_api_key_here
ANKR_MIDNIGHT_MAINNET_WSS=wss://rpc.ankr.com/midnight_mainnet/your_project_api_key_here

Build URLs in code if you only store the key:

const ANKR_KEY = process.env.ANKR_API_KEY!;
if (!ANKR_KEY) throw new Error('Missing ANKR_API_KEY');

export const ANKR_MIDNIGHT = {
  testnet: {
    http: `https://rpc.ankr.com/midnight_testnet/${ANKR_KEY}`,
    wss: `wss://rpc.ankr.com/midnight_testnet/${ANKR_KEY}`,
  },
  mainnet: {
    http: `https://rpc.ankr.com/midnight_mainnet/${ANKR_KEY}`,
    wss: `wss://rpc.ankr.com/midnight_mainnet/${ANKR_KEY}`,
  },
} as const;

2) Smoke-test the endpoint

curl -X POST "https://rpc.ankr.com/midnight_testnet/${ANKR_API_KEY}/" \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "system_chain",
    "params": [],
    "id": 1
  }'

Expected shape:

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": "testnet-02-1"
}

Quick health check:

curl -X POST "https://rpc.ankr.com/midnight_testnet/${ANKR_API_KEY}/" \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","method":"system_health","params":[],"id":1}'

3) Minimal TypeScript JSON-RPC client (Midnight)

No @ankr.com/ankr.js required for Midnight.

type JsonRpcId = number | string;

export async function ankrMidnightRpc<T = unknown>(
  endpoint: string,
  method: string,
  params: unknown[] = [],
  id: JsonRpcId = 1,
): Promise<T> {
  const res = await fetch(endpoint, {
    method: 'POST',
    headers: { 'content-type': 'application/json' },
    body: JSON.stringify({ jsonrpc: '2.0', method, params, id }),
  });

  if (!res.ok) {
    throw new Error(`Ankr RPC HTTP ${res.status}: ${await res.text()}`);
  }

  const payload = (await res.json()) as {
    result?: T;
    error?: { code: number; message: string; data?: unknown };
  };

  if (payload.error) {
    throw new Error(`Ankr RPC ${payload.error.code}: ${payload.error.message}`);
  }

  return payload.result as T;
}

Usage:

const rpc = process.env.ANKR_MIDNIGHT_TESTNET_RPC!;

const chain = await ankrMidnightRpc<string>(rpc, 'system_chain');
const health = await ankrMidnightRpc<{
  peers: number;
  isSyncing: boolean;
  shouldHavePeers: boolean;
}>(rpc, 'system_health');

const apiVersions = await ankrMidnightRpc<number[]>(rpc, 'midnight_apiVersions');

4) Wire Ankr into midnight-js / multinetwork config

Midnight dApps typically need three services. Ankr replaces only the node RPC:

ServiceProviderNotes
Node RPCAnkr (this skill)midnight_*, system_*, tx submit paths used by SDKs
Indexer GraphQLMidnight hosted indexerStill indexer.*.midnight.network — not Ankr
Proof serverLocal Docker or 1AMUnchanged

Drop-in network config

import { ANKR_MIDNIGHT } from './ankr';

// Map Ankr "testnet" to your app's Midnight testnet target
// (preview/preprod naming differs by SDK version — use the network your app deploys to)
export const networks = {
  testnet: {
    // Keep official indexer unless you have another GraphQL provider
    indexerHttp: 'https://indexer.preprod.midnight.network/api/v4/graphql',
    indexerWs: 'wss://indexer.preprod.midnight.network/api/v4/graphql/ws',
    // Ankr node RPC (HTTPS). Some midnight-js setups expect WSS — use ANKR_MIDNIGHT.testnet.wss then.
    rpc: ANKR_MIDNIGHT.testnet.http,
    proofServerUrl: 'http://127.0.0.1:6300',
  },
  mainnet: {
    indexerHttp: 'https://indexer.mainnet.midnight.network/api/v4/graphql',
    indexerWs: 'wss://indexer.mainnet.midnight.network/api/v4/graphql/ws',
    rpc: ANKR_MIDNIGHT.mainnet.http,
    proofServerUrl: 'https://api.1am.xyz',
  },
};

Where example skills use node = 'https://rpc.preprod.midnight.network', replace with the Ankr HTTPS URL (or WSS if the provider builder requires WebSocket).

Network naming note: Ankr exposes midnight_testnet / midnight_mainnet. Midnight apps often use preview / preprod / mainnet. Confirm which public Midnight network Ankr’s midnight_testnet tracks (system_chain → e.g. testnet-02-1) before deploying contracts against it.


5) Operations (JSON-RPC methods on Ankr Midnight)

Full method catalog: Ankr Midnight docs and skill midnight-rpc/.

A) Midnight-specific (primary for dApps)

MethodPurposeTypical params
midnight_apiVersionsSupported Midnight RPC API versions[]
midnight_contractStateRaw/binary contract state at optional block[contractAddress, atBlockHash?]
midnight_jsonContractStateHuman-readable JSON contract state[contractAddress, atBlockHash?]
midnight_zswapChainStateZSwap chain state for a contract[contractAddress, atBlockHash?]
midnight_jsonBlockFull block as JSON[blockHashOrNumber]
midnight_decodeEventsDecode Midnight contract events[eventPayload…] (see node docs)
const state = await ankrMidnightRpc(
  rpc,
  'midnight_jsonContractState',
  ['<contract-address>'], // omit second arg for latest
);

const zswap = await ankrMidnightRpc(
  rpc,
  'midnight_zswapChainState',
  ['<contract-address>'],
);

const versions = await ankrMidnightRpc(rpc, 'midnight_apiVersions');

B) System / health

MethodPurpose
system_chainChain name (e.g. testnet-02-1)
system_chainTypeLive / Development / Local
system_healthSync + peer health
system_propertiesChain properties
system_syncStatestartingBlock / currentBlock / highestBlock
system_versionNode implementation version
await ankrMidnightRpc(rpc, 'system_chain');
await ankrMidnightRpc(rpc, 'system_syncState');

C) Chain & blocks

MethodPurpose
chain_getBlockFull block by hash
chain_getBlockHashHash for block number
chain_getHeaderBlock header
chain_getFinalizedHead / chain_getFinalisedHeadLatest finalized hash
chain_getHeadBest block hash
chain_getRuntimeVersionRuntime version
const head = await ankrMidnightRpc<string>(rpc, 'chain_getFinalizedHead');
const block = await ankrMidnightRpc(rpc, 'chain_getBlock', [head]);

D) State & storage

MethodPurpose
state_getStorage / state_getStorageAtRead storage key
state_getKeysPaged / state_getKeysPagedAtPage storage keys
state_getMetadataRuntime metadata
state_call / state_callAtRuntime call without extrinsic
state_queryStorageAtMulti-key query at block

E) Archive (historical)

MethodPurpose
archive_unstable_finalizedHeightLatest archived finalized height
archive_unstable_genesisHashGenesis hash
archive_unstable_hashByHeightHash(es) at height
archive_unstable_header / archive_unstable_bodyHistorical header / extrinsics
archive_unstable_call / archive_unstable_storageHistorical runtime call / storage

F) Sidechain / Partnerchain

MethodPurpose
sidechain_getStatusSidechain sync / status
sidechain_getParamsSidechain config params
sidechain_getEpochCommitteeValidator committee for epoch
sidechain_getRegistrationsRegistered participants
sidechain_getAriadneParametersAriadne parameters

G) Accounts, GRANDPA, child state, meta

MethodPurpose
account_nextIndex / system_accountNextIndexNext account nonce
grandpa_proveFinality / grandpa_roundStateFinality proofs / round state
childstate_getStorage (+ keys/hash/size variants)Child storage reads
rpc_methodsList methods exposed by this Ankr node
offchain_localStorageGet / SetOften restricted on public RPCs
const methods = await ankrMidnightRpc(rpc, 'rpc_methods');

6) What Ankr does not replace on Midnight

NeedUse instead
Contract actions, tx history, live subscriptionsMidnight Indexer GraphQL (indexer/ skill)
NFT/token portfolio APIs like getNFTsByOwnerNot available via Ankr Advanced API for Midnight
Proof generationLocal proof server or 1AM ProofStation
Compact compile / deploycompact/, midnight-js/

Troubleshooting

SymptomCauseFix
401 / unauthorizedBad or missing API key in pathRecopy endpoint from Ankr Projects → Midnight
method not foundMethod not exposed on this nodeCall rpc_methods; fall back to official Midnight RPC
Advanced API / AnkrProvider errors with MidnightWrong productUse Chain RPC JSON-RPC, not @ankr.com/ankr.js Advanced API
App works on official RPC, fails on AnkrHTTPS vs WSS mismatchMatch protocol expected by midnight-js provider (http vs ws)
Rate limit / 429Free tier or empty credit balanceUpgrade plan / deposit API credits
Indexer queries fail after switching RPCIndexer URL accidentally pointed at AnkrKeep indexer on indexer.*.midnight.network
Wrong chain / contracts missingAnkr testnet ≠ your preview/preprod deployVerify with system_chain and redeploy or switch network

Related Skills

TaskSkill
Midnight JSON-RPC method semanticsmidnight-rpc/
Provider wiring, wallets, deploymidnight-js/
Multi-network RPC/indexer/proof configmultinetwork/
GraphQL reads & subscriptionsindexer/
Environment / proof server setupmidnight-environment-setup/

Sources

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.