The official TypeScript SDK for interacting with the PolkaMesh confidential compute network.
- Confidential Compute: Submit encrypted jobs to Phala TEE workers.
- MEV Protection: Submit intents for fair batching and sandwich attack protection.
- Attestation Verification: Verify cryptographic proofs of execution.
- Type Safety: Full TypeScript support with generated types.
npm install @polkamesh/sdk
# or
yarn add @polkamesh/sdkCreate a .env file in your project root:
# Polkadot Network
RPC_URL=wss://rpc1.paseo.popnetwork.xyz
# Core Contracts (Ink! v6)
PAYMENT_ESCROW=0x5a86a13ef7fc1c5e58f022be183de015dfb702ae
AI_JOB_QUEUE=0xa44639cd0d0e6c6607491088c9c549e184456122
COMPUTE_PROVIDER_REGISTRY=0x2c6fc00458f198f46ef072e1516b83cd56db7cf5
DATA_NFT_REGISTRY=0x6dc84ddeffccb19ed5285cf3c3d7b03a57a9a4b1
# Advanced Contracts (Ink! v5)
MEV_PROTECTION=5DTPZHSHydkPQZbTFrhnHtZiDER7uoKSzdYHuCUXVAtjajXs
PHALA_JOB_PROCESSOR=5HrKZAiTSAFcuxda89kSD77ZdygRUkufwRnGKgfGFR4NC2np
# Phala Phat Contract (Off-chain TEE)
PHALA_PHAT_CONTRACT_ID=app_4c48fd1fdbcf7495e90758c6b4108faf1205c3a3
PHALA_WORKER_ENDPOINT=https://phala-worker-api.phala.network
PHALA_CLUSTER_ID=poc6-testnetimport { createPolkaMesh } from '@polkamesh/sdk';
const sdk = await createPolkaMesh({
rpcUrl: process.env.RPC_URL,
contractAddresses: {
paymentEscrow: process.env.PAYMENT_ESCROW,
aiJobQueue: process.env.AI_JOB_QUEUE,
computeProviderRegistry: process.env.COMPUTE_PROVIDER_REGISTRY,
dataNFTRegistry: process.env.DATA_NFT_REGISTRY,
mevProtection: process.env.MEV_PROTECTION,
phalaJobProcessor: process.env.PHALA_JOB_PROCESSOR,
},
phatConfig: {
contractId: process.env.PHALA_PHAT_CONTRACT_ID,
workerEndpoint: process.env.PHALA_WORKER_ENDPOINT,
clusterId: process.env.PHALA_CLUSTER_ID,
}
});const aiJobQueue = sdk.getAIJobQueue();
const job = await aiJobQueue.submitJob({
description: 'Train ML model on encrypted dataset',
budget: '10000000000000000', // 10 DOT
dataSetId: '123',
computeType: 'GPU_V100',
});
console.log('Job ID:', job.jobId);const phala = sdk.getPhalaJobProcessor();
const result = await phala.submitConfidentialJob({
model: 'gpt-2',
input: 'Sensitive user data',
requirements: { memory: 16384, gpu: 'T4' }
});
console.log('Job ID:', result.jobId);
console.log('Encrypted:', result.encryptedPayload);const attestation = await phala.getAttestation(jobId);
if (attestation.valid) {
console.log('Execution verified!', attestation.proof);
}const mev = sdk.getMEVProtection();
// Submit a trade intent
const intentId = await mev.submitIntent({
tokenIn: 'DOT',
tokenOut: 'USDT',
amountIn: '10000000000',
minAmountOut: '50000000',
});
console.log('Intent submitted:', intentId);The SDK wraps interactions with three main components:
- MEV Protection Contract (Ink!): Handles intent aggregation.
- Phala Job Processor (Ink!): Orchestrates off-chain computation.
- Phat Contract (Rust/WASM): Executes logic inside TEE.
- ECIES Encryption: All confidential data is encrypted using Elliptic Curve Integrated Encryption Scheme.
- Remote Attestation: Execution results are signed by the TEE hardware.
- On-Chain Verification: Proofs are verified on-chain before payment release.
MIT