AGENT REFERENCE
Skill
A structured reference for autonomous agents. Read this page to understand how to deploy, publish, consume, and browse Mindstate streams programmatically.
Overview
Mindstate is an Ethereum ERC-20 extension (ERC-3251) and TypeScript SDK for publishing encrypted AI artifacts as a versioned, append-only checkpoint stream. The on-chain contract stores commitments, storage URIs, and redemption records. The SDK handles deterministic serialization (RFC 8785), AES-256-GCM encryption, storage upload (IPFS, Arweave, or Filecoin), on-chain checkpoint publication, X25519 key wrapping for consumer delivery, and commitment verification. Secrets never appear on-chain. Access is gated by burning ERC-20 tokens.
Repository: github.com
Package: @mindstate/sdk
Core Types
The fundamental data structures used across the SDK.
interface Capsule {
version: string; // Protocol version ("1.0.0")
schema?: string; // Optional: "agent/v1", "model-weights/v1", etc.
payload: Record<string, unknown>; // Anything you want
}
interface IdentityKernel {
id: string; // Persistent identifier (bytes32 hex)
constraints: Record<string, unknown>;
selfAmendmentRules?: Record<string, unknown>;
signature?: string;
}
interface ExecutionManifest {
modelId: string; // e.g. "gpt-4o"
modelVersion: string;
toolVersions: Record<string, string>;
determinismParams: Record<string, unknown>;
environment: Record<string, unknown>;
timestamp: string; // ISO 8601
}
// On-chain checkpoint record
struct Checkpoint {
bytes32 predecessorId; // Prior checkpoint (bytes32(0) for genesis)
bytes32 stateCommitment; // keccak256 of canonical plaintext
bytes32 ciphertextHash; // Hash of encrypted payload
string ciphertextUri; // Storage URI (IPFS CID, ar://, fil://)
bytes32 manifestHash; // Optional secondary commitment
uint64 publishedAt; // block.timestamp
uint64 blockNumber; // block.number
}
enum RedeemMode {
PerCheckpoint, // Each redeem() burns tokens for one checkpoint
Universal // One redeem() grants access to all checkpoints
}Deploy a Stream
STEP 1Deploy the implementation contract once, then use the factory for gas-efficient EIP-1167 clones (~100K gas per stream).
import {IMindstate} from "./interfaces/IMindstate.sol";
MindstateToken impl = new MindstateToken();
MindstateFactory factory = new MindstateFactory(address(impl));
// Create a per-checkpoint stream
// 1M tokens, 100 burned per redemption
address token = factory.create(
"Agent Alpha Access", // name
"ALPHA", // symbol
1_000_000e18, // totalSupply
100e18, // redeemCost
IMindstate.RedeemMode.PerCheckpoint
);Parameters: name and symbol are standard ERC-20. totalSupply is minted to the deployer. redeemCost is the number of tokens burned per redeem() call. RedeemMode is either PerCheckpoint or Universal.
Publish a Checkpoint
STEP 2Serialize a capsule, encrypt it, upload to storage, and commit on-chain.
import {
MindstateClient, createCapsule, createAgentCapsule,
generateEncryptionKeyPair,
PublisherKeyManager, StorageKeyDelivery, IpfsStorage,
} from '@mindstate/sdk';
// IPFS is the default; ArweaveStorage and FilecoinStorage also available
const storage = new IpfsStorage({
gateway: 'https://ipfs.io',
apiUrl: 'http://localhost:5001',
});
const publisherKeys = generateEncryptionKeyPair();
const delivery = new StorageKeyDelivery(storage);
const keyManager = new PublisherKeyManager(publisherKeys, delivery);
// Generic capsule — any payload
const capsule = createCapsule(
{ model: 'gpt-4-turbo', weights: '...', config: { temperature: 0 } },
{ schema: 'model-weights/v1' },
);
// Or use the agent/v1 convention
const agentCapsule = createAgentCapsule({
identityKernel: {
id: '0xabc...def',
constraints: { purpose: 'assistant' },
},
executionManifest: {
modelId: 'gpt-4-turbo',
modelVersion: '2025-01-01',
toolVersions: {},
determinismParams: { temperature: 0 },
environment: {},
timestamp: new Date().toISOString(),
},
});
// Publish: serialize → encrypt → upload → commit
const client = new MindstateClient({ provider, signer });
const { checkpointId, sealedCapsule } =
await client.publish(tokenAddress, capsule, { storage });
// Store the encryption key for future consumer deliveries
keyManager.storeKey(checkpointId, sealedCapsule.encryptionKey);Fulfill Redemptions
STEP 3When a consumer burns tokens on-chain, the publisher wraps the decryption key and uploads the envelope.
// Listen for Redeemed events, then for each:
const consumerPubKey = await client.getEncryptionKey(
tokenAddress,
consumerAddress,
);
await keyManager.fulfillRedemption(
tokenAddress,
checkpointId,
consumerAddress,
ethers.getBytes(consumerPubKey),
);
// Publish the updated index so consumers can discover envelopes
const indexUri = await delivery.publishIndex();The publisher must be online to observe redemption events and fulfill them. Key escrow or threshold networks can mitigate publisher availability requirements.
Consume a Checkpoint
STEP 4Redeem access by burning tokens, fetch the key envelope, decrypt, and verify.
import {
MindstateClient, StorageKeyDelivery, IpfsStorage,
generateEncryptionKeyPair,
} from '@mindstate/sdk';
// Any StorageProvider works — IPFS, Arweave, Filecoin, or StorageRouter
const storage = new IpfsStorage({
gateway: 'https://ipfs.io',
apiUrl: 'http://localhost:5001',
});
// Load the publisher's key index
const delivery = new StorageKeyDelivery(storage);
await delivery.loadIndex(publisherIndexUri);
// Generate consumer encryption keys
const consumerKeys = generateEncryptionKeyPair();
// Consume: redeem (burn) → fetch envelope → decrypt → verify
const client = new MindstateClient({ provider, signer });
const head = await client.getHead(tokenAddress);
const { capsule } = await client.consume(tokenAddress, head, {
keyDelivery: delivery,
encryptionKeyPair: consumerKeys,
storage,
});
// capsule is verified and ready — the agent can be resumedBrowse and Discover
STEP 5Read-only exploration of checkpoint streams without consuming access.
import { MindstateExplorer } from '@mindstate/sdk';
const explorer = new MindstateExplorer(provider);
// Full timeline (oldest first)
const timeline = await explorer.getTimeline(tokenAddress);
// 5 most recent checkpoints
const recent = await explorer.getRecent(tokenAddress, 5);
// Resolve a tag to its checkpoint
const stable = await explorer.resolveTag(tokenAddress, 'stable');
// Walk lineage from any checkpoint back to genesis
const lineage = await explorer.getLineage(tokenAddress, checkpointId);
// Enriched timeline — on-chain tags + off-chain descriptions
const enriched = await explorer.getEnrichedTimeline(tokenAddress, {
storage,
indexUri: publisherIndexUri,
});Indexer REST API
For applications that need fast queries across many tokens, run the standalone indexer service. REST API at http://localhost:3000:
cd indexer && npm install && npm run build
FACTORY_ADDRESS=0x... RPC_URL=https://... npm start