Publish an Encrypted Blob
Encrypt application state locally, encode a 2D TCDA matrix, sign anchor_blob, and track attestation to Available status.
This guide covers publishing an encrypted blob from a Solana application using @alder/sdk, handling wallet signing of the unsigned v0 anchor_blob transaction, confirming quorum attestation, and cancelling a timed-out blob if needed.
Prerequisites
@alder/sdkand@alder/contractinstalled in your TypeScript project@solana/web3.js(or a Wallet Standard browser wallet) to deserialize and sign the v0 transaction- A funded Solana publisher wallet with enough SOL to cover the availability fee plus
BlobRecordPDA rent (223bytes)
1. Encrypt, Encode, and Build anchor_blob
Call sdk.putPrivateBlob. It runs AES-256-GCM encryption and GF(256) 2D Reed-Solomon encoding entirely in your runtime, then calls POST /v1/blobs/anchor/build with the coded cells and commitments:
import { createAlderSdk } from '@alder/sdk'
const sdk = createAlderSdk('http://127.0.0.1:42102')
const payload = JSON.stringify({
type: 'rollup-state-diff',
batch: 812,
root: '0x9a4f...c201',
})
const published = await sdk.putPrivateBlob({
publisher: walletPublicKeyBase58,
payload,
k: 4, // 4x4 data -> 8x8 coded matrix (64 cells)
retentionDepth: 2, // 2x coded shard replication across bonded nodes
policyId: 'private', // or 'privacy-rings', 'auditor-scoped', 'public-audit'
expirySlots: 216_000, // default ~1 epoch factor
})Save published.contentKeyBase64 and published.blobId in your application's local secret storage immediately. The API receives only ciphertext cells, nonceBase64, and commitments.
Choosing Coding Parameters
| Field | Range | Default | Effect |
|---|---|---|---|
k | 2..16 | 4 | Matrix expands to n = 2k (4..32), producing n^2 cells (16..1024) |
retentionDepth | 1..4 | 2 | Number of bonded DA nodes holding each cell; scales fee linearly |
expirySlots | 100..50,000,000 | 216,000 | Slots from anchor_slot until expiry_slot; scales fee per 216,000-slot factor |
policyId | 1..64 chars | 'private' | Hashed to policy_id_hash on chain; binds compliance or Privacy Rings metadata |
2. Sign and Submit the v0 Transaction
Deserialize published.txBuild.transactionBase64, sign it with the publisher wallet (always let the wallet sign first), and relay it via sdk.api.submitTransaction:
import { VersionedTransaction } from '@solana/web3.js'
import { fromBase64, toBase64 } from '@alder/contract'
const txBytes = fromBase64(published.txBuild.transactionBase64)
const tx = VersionedTransaction.deserialize(txBytes)
// Browser Wallet Standard or local Keypair sign
const signedTx = await wallet.signTransaction(tx)
const signedBase64 = toBase64(signedTx.serialize())
const txStatus = await sdk.api.submitTransaction({
id: published.txBuild.id,
signedTransactionBase64: signedBase64,
})
console.log('tx status:', txStatus.status, 'signature:', txStatus.signature)You can poll sdk.api.getTransaction(published.txBuild.id) until status is confirmed or finalized.
3. Automatic On-Chain Attestation
When POST /v1/transactions/submit confirms an anchor_blob transaction on Solana, the backend verifies the confirmed instruction bytes and accounts, verifies the staged coded cells against commitmentRoot and verifyTcdaCodeword, and automatically executes on-chain attest_availability (co-signed by authority and the custodian node operator).
txStatus returns the attestation details directly:
console.log('anchor signature:', txStatus.signature)
console.log('attestation signature:', txStatus.attestationSignature)
console.log('attestation slot:', txStatus.attestationSlot)
console.log('latency (ms):', txStatus.attestationLatencyMs)To subscribe to real-time attestation updates without polling, open an EventSource on sdk.api.eventsUrl(published.blobId) and parse the { type, id, timestamp, data } JSON envelope for type === 'blob.attested'.
4. Handling Unattested Timeouts (cancel_blob) and Rent Recovery (close_blob)
If a Pending blob is not attested before blob.attestation_deadline_slot, reclaim the full escrowed SOL fee:
const cancelBuild = await sdk.api.buildCancelBlob(published.blobId, {
publisher: walletPublicKeyBase58,
})
// Sign cancelBuild.transactionBase64 and submit via sdk.api.submitTransactionCalling cancel_blob before attestation_deadline_slot elapses returns AlderError::AttestationWindowActive (6015). Once a blob is Expired or Cancelled with escrowed_fee == 0 and open_challenge_count == 0, the publisher can call close_blob to reclaim the BlobRecord PDA rent.
Common Errors
| Code | HTTP | Cause | Fix |
|---|---|---|---|
VALIDATION_ERROR | 400 | payloadSizeBytes > 4,194,304, invalid blobId regex, or k/retentionDepth out of bounds | Check k (2..16), retentionDepth (1..4), and blobId (^[a-zA-Z0-9_-]+$) |
SIMULATION_FAILED | 422 | Insufficient SOL for fee + BlobRecord PDA rent or duplicate blobId for same publisher | Fund publisher wallet or use a fresh blobId |
TRANSACTION_EXPIRED | 409 | Blockhash passed lastValidBlockHeight before submission | Re-call putPrivateBlob or buildAnchorBlob for a fresh blockhash |
Next Steps
- Verify your anchored blob from a light client in Run a DAS Light Client.
- Issue an auditor viewing key in Selective Disclosure.