Loading...
Loading...
Build encrypted Solana frontends with Arcium. Use when creating Arcium apps, encrypting user inputs, deriving PDAs, integrating wallets, or troubleshooting Arcium transactions.
npx skill4agent add sicmundu/arcium-skills-frontend arcium-frontendnpm install @arcium-hq/client @coral-xyz/anchor @solana/web3.js| Variable | Required | Default |
|---|---|---|
| Yes | — |
| Yes | — |
| No | devnet |
getMXEPublicKey(provider, programId)import * as anchor from '@coral-xyz/anchor';
import { PublicKey, SystemProgram } from '@solana/web3.js';
import {
getMXEPublicKey,
getClusterAccAddress,
getMXEAccAddress,
getMempoolAccAddress,
getExecutingPoolAccAddress,
getComputationAccAddress,
getCompDefAccAddress,
getArciumAccountBaseSeed,
getCompDefAccOffset,
getArciumProgramId,
x25519,
RescueCipher,
deserializeLE,
} from '@arcium-hq/client';// 1. Fetch MXE public key
const mxePublicKey = await getMXEPublicKey(provider, programId);
// 2. Generate ephemeral keypair
const privateKey = x25519.utils.randomPrivateKey();
const publicKey = x25519.getPublicKey(privateKey);
// 3. Derive shared secret
const sharedSecret = x25519.getSharedSecret(privateKey, mxePublicKey);
// 4. Encrypt values
const cipher = new RescueCipher(sharedSecret);
const nonce = nacl.randomBytes(16);
const values = [BigInt(10), BigInt(7), BigInt(5)];
const ciphertexts = cipher.encrypt(values, nonce);// Cluster-based PDAs
const clusterOffset = 768109697; // from ARCIUM_CLUSTER_OFFSET
const clusterAccount = getClusterAccAddress(clusterOffset);
const mempoolAccount = getMempoolAccAddress(clusterOffset);
const executingPool = getExecutingPoolAccAddress(clusterOffset);
// Program-based PDAs
const mxeAccount = getMXEAccAddress(programId);
const computationOffset = new anchor.BN(nacl.randomBytes(8), 'le');
const computationAccount = getComputationAccAddress(clusterOffset, computationOffset);
// Comp def account
const baseSeed = getArciumAccountBaseSeed('ComputationDefinitionAccount');
const offsetBytes = getCompDefAccOffset('my_computation');
const [compDefAccount] = PublicKey.findProgramAddressSync(
[baseSeed, programId.toBuffer(), offsetBytes],
getArciumProgramId()
);payermxeAccountmempoolAccountexecutingPoolcomputationAccountcompDefAccountclusterAccountSystemProgram.programIdarciumProgramId| Error | Cause | Solution |
|---|---|---|
| Missing env var | Add to |
| MXE not initialized | Initialize MXE account first |
| Wrong PDA derivation | Check cluster offset matches network |