Preimage docs
Look up any call, event, or storage item with code examples. Runtime v472 · Block #9,197,056
Developer documentation for the Preimage pallet of the Subtensor blockchain, part of the Bittensor decentralized AI network. This page is designed for developers integrating with the chain: look up any call, event, or storage item, copy code examples in TypeScript, Python, or Rust, and filter by your role. For in-depth explanations, version history, and relationships between items, see the Reference section.
Preimage
Register a preimage on-chain.
Calls 5
Stores a preimage on-chain.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
bytes | Vec<u8> | Array of Integer (0-255) | bytes (Vec<u8>) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build note_preimage call (typed, named args)
const bytes = Binary.fromOpaque(new Uint8Array(0));
const tx = api.tx.Preimage.note_preimage({
bytes,
});Removes an unrequested preimage.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
hash | H256 | 256-bit Hash | hash: Cryptographic hash (32 bytes) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build unnote_preimage call (typed, named args)
const hash = "0x0000000000000000000000000000000000000000000000000000000000000000";
const tx = api.tx.Preimage.unnote_preimage({
hash,
});Requests a preimage for use.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
hash | H256 | 256-bit Hash | hash: Cryptographic hash (32 bytes) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build request_preimage call (typed, named args)
const hash = "0x0000000000000000000000000000000000000000000000000000000000000000";
const tx = api.tx.Preimage.request_preimage({
hash,
});Removes request for a preimage.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
hash | H256 | 256-bit Hash | hash: Cryptographic hash (32 bytes) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build unrequest_preimage call (typed, named args)
const hash = "0x0000000000000000000000000000000000000000000000000000000000000000";
const tx = api.tx.Preimage.unrequest_preimage({
hash,
});Ensures preimage status is current.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
hashes | Vec<H256> | Array of 256-bit Hash | hashes: list of Cryptographic hash (32 bytes) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build ensure_updated call (typed, named args)
const hashes = [] as [];
const tx = api.tx.Preimage.ensure_updated({
hashes,
});Events 3
A preimage has been stored on-chain.
When it fires
- Data provided
- Hash unique
Fields
| Name | Type | Format | Description |
|---|---|---|---|
hash | H256 | 256-bit Hash | hash: Cryptographic hash (32 bytes) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Subscribe to Noted events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Preimage.Noted.get(block.hash);
for (const evt of events) {
console.log("Noted:", evt.payload);
}
});A preimage has been requested.
When it fires
- Hash provided
Fields
| Name | Type | Format | Description |
|---|---|---|---|
hash | H256 | 256-bit Hash | hash: Cryptographic hash (32 bytes) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Subscribe to Requested events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Preimage.Requested.get(block.hash);
for (const evt of events) {
console.log("Requested:", evt.payload);
}
});A preimage has been cleared.
When it fires
- Preimage exists
- Not requested
Fields
| Name | Type | Format | Description |
|---|---|---|---|
hash | H256 | 256-bit Hash | hash: Cryptographic hash (32 bytes) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Subscribe to Cleared events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Preimage.Cleared.get(block.hash);
for (const evt of events) {
console.log("Cleared:", evt.payload);
}
});Storage 3
Actual preimage data stored by (hash, length).
BoundedVec Keys
| Name | Type | Format | Description |
|---|---|---|---|
key1 | H256 | 256-bit Hash | — |
key2 | u32 | Integer | — |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Query PreimageFor storage
const key1 = "0x0000000000000000000000000000000000000000000000000000000000000000";
const key2 = 0;
const result = await api.query.Preimage.PreimageFor.getValue(key1, key2);
console.log("PreimageFor:", result);Request status for preimages.
RequestStatus Keys
| Name | Type | Format | Description |
|---|---|---|---|
key1 | H256 | 256-bit Hash | — |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Query RequestStatusFor storage
const key1 = "0x0000000000000000000000000000000000000000000000000000000000000000";
const result = await api.query.Preimage.RequestStatusFor.getValue(key1);
console.log("RequestStatusFor:", result);Status of a preimage by hash (deprecated).
OldRequestStatus Keys
| Name | Type | Format | Description |
|---|---|---|---|
key1 | H256 | 256-bit Hash | — |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Query StatusFor storage
const key1 = "0x0000000000000000000000000000000000000000000000000000000000000000";
const result = await api.query.Preimage.StatusFor.getValue(key1);
console.log("StatusFor:", result);Errors 8
The preimage data exceeds the maximum allowed size. Preimages store encoded call data for deferred execution (e.g., governance proposals) and have a size limit to prevent state bloat.
Common Causes
- Proposal call data is too large when SCALE-encoded
- Trying to store a batch call with too many sub-calls
- Embedded data (like code upgrades) exceeds the limit
How to Fix
Reduce the size of the call data (e.g., fewer batch calls),Split large operations into multiple smaller proposals,Check the MaxSize constant for the current limit
A preimage with this hash has already been stored. Preimages are identified by the Blake2 hash of their content, so identical call data will always produce the same hash.
Common Causes
- Submitting the same preimage (call data) that was already stored
- Another account already noted this exact preimage
- Accidentally calling note_preimage twice
How to Fix
Query Preimage.StatusFor with the hash to confirm it exists,Use the existing preimage — no need to store it again,If you need a different preimage, modify the call parameters
You are not authorized to remove (unnote) this preimage. Only the account that originally stored the preimage and paid the deposit can remove it.
Common Causes
- Trying to unnote a preimage that was stored by a different account
- Using the wrong account to sign the unnote transaction
How to Fix
Query Preimage.StatusFor to find the depositor account,Sign the unnote transaction with the original depositor account,If the preimage is no longer needed and you are not the depositor, the depositor must remove it
No preimage exists with this hash. The preimage was either never stored, already removed, or the hash is incorrect.
Common Causes
- Wrong preimage hash
- Preimage was already removed (unnoted) by its depositor
- Preimage was never stored in the first place
How to Fix
Query Preimage.StatusFor to check if the hash exists,Verify the hash matches the expected call data,Store the preimage first using note_preimage if it does not exist
This preimage is currently requested by the governance system (e.g., a pending proposal references it). It cannot be removed while something depends on it.
Common Causes
- Trying to unnote a preimage that is referenced by an active governance proposal
- A scheduled call depends on this preimage data
- The preimage has active request references
How to Fix
Wait for the governance proposal or scheduled call to execute or be cancelled,Query Preimage.RequestStatusFor to check who is requesting it,The preimage will become removable after all requesters release it
The preimage you are trying to unrequest is not currently in a requested state. It was either never requested or already unrequested.
Common Causes
- The request reference was already released
- The preimage was never requested by this mechanism
- The governance action that requested it was already completed
How to Fix
Query Preimage.RequestStatusFor to check the request status,No action needed if the request was already released
The preimage has too many outstanding request references. There is a maximum number of concurrent requesters allowed per preimage.
Common Causes
- Multiple governance mechanisms all requesting the same preimage simultaneously
- Request reference count overflow
How to Fix
Wait for some requesters to release their references,Query Preimage.RequestStatusFor to check the current reference count
Cannot decrease the request reference count below zero. This typically indicates an internal bookkeeping issue where unrequest was called more times than request.
Common Causes
- Unrequest called without a matching request
- Internal reference count underflow
How to Fix
Query Preimage.RequestStatusFor to check the current reference count,This is likely a bug — report it if encountered in normal operation