Learn Shadow Protocol by running live code examples. Each example includes step-by-step explanations and editable code.
Create a privacy-preserving sealed auction with encrypted bids
import { ShadowProtocolClient } from '@shadow-protocol/client';
import { Connection, PublicKey } from '@solana/web3.js';
// Initialize client
const client = new ShadowProtocolClient({
rpcUrl: 'https://api.devnet.solana.com',
arciumClusterPubkey: process.env.NEXT_PUBLIC_ARCIUM_CLUSTER_PUBKEY!,
wallet: yourWallet,
});
// Create sealed auction
const auction = await client.createSealedAuction({
assetMint: new PublicKey('So11111111111111111111111111111111111111112'),
duration: 3600, // 1 hour
minimumBid: 1_000_000, // 1 SOL
reservePrice: 5_000_000, // 5 SOL (encrypted)
});
console.log(`Auction created: ${auction.auctionId}`);
// Submit encrypted bid
const bid = await client.submitEncryptedBid({
auctionId: auction.auctionId.toString(),
amount: 7_000_000, // 7 SOL
});
console.log(`Bid submitted: ${bid.signature}`);
1. Client Initialization: Creates a connection to Solana and sets up the Arcium MPC client for encryption.
2. Reserve Price Encryption: The reserve price is encrypted client-side using Arcium's MPC before being sent to the blockchain.
3. Auction Creation: The auction is created on-chain with the encrypted reserve price. Only the MPC network can decrypt it during settlement.
4. Encrypted Bidding: Bid amounts are encrypted client-side, ensuring complete privacy until settlement.