Export a large NEAR contract state without mixing blocks
A contract can change between two pages of storage keys. A complete export needs both a continuation key and a fixed block for the entire read.
Capture the first page and its block
Use an endpoint supporting paginated view_state (nearcore 2.13.0 or later). Substitute the contract account. An empty prefix selects all keys. A nonempty prefix represents the raw key prefix encoded in base64.
{
"jsonrpc": "2.0",
"id": 1,
"method": "query",
"params": {
"request_type": "view_state",
"finality": "final",
"account_id": "ledger.testnet",
"prefix_base64": "",
"limit": 100
}
}
Carry the server’s cursor forward
Write the values and the returned block_hash to your export. If a last_key is present, send it unchanged as after_key_base64. Replace finality with block_id equal to the saved hash on subsequent pages. Keep the account and prefix fixed until the server returns no continuation key.
For example, a cursor Yg== represents one byte, b. Encoding the text Yg== again would pass four different bytes. Commit rows and continuation together so a retry cannot leave the cursor ahead of stored data.