Skip to main content

deployAppAuth

Deploys an AppAuth smart contract on Ethereum or Base. This is required for on-chain KMS deployments — the contract acts as the access-control layer and generates the app_id used in commitCvmProvision. This function interacts directly with the blockchain (not the Phala Cloud API). Parameters:
FieldTypeRequiredDescription
chainChainConditionalViem chain config (required if no walletClient)
kmsContractAddressAddressYesKMS factory contract address
privateKeyHexConditionalDeployer private key (provide this or walletClient)
walletClientWalletClientConditionalCustom wallet client (provide this or privateKey)
rpcUrlstringNoCustom RPC URL
publicClientPublicClientNoCustom public client
deviceIdstringNoDevice ID for access control (default: 32 zero bytes)
composeHashstringNoApp compose hash (default: 32 zero bytes)
allowAnyDevicebooleanNoAllow any device (default: false)
disableUpgradesbooleanNoMake contract immutable (default: false)
skipPrerequisiteChecksbooleanNoSkip balance/chain checks (default: false)
minBalancestringNoMinimum ETH balance required (default: "0.001")
timeoutnumberNoTransaction timeout in ms
retryOptionsobjectNoRetry configuration
Callbacks:
CallbackDescription
onTransactionStateChangeCalled when transaction state changes
onTransactionSubmittedCalled when transaction is submitted to mempool
onTransactionConfirmedCalled when transaction is confirmed on-chain
Returns: DeployAppAuth
FieldTypeDescription
appIdstringGenerated app ID (use in commitCvmProvision)
appAuthAddressstringDeployed contract address
deployerstringDeployer wallet address
transactionHashstringDeployment transaction hash
blockNumberbigint?Block number of confirmation
gasUsedbigint?Gas consumed
Example:
import { deployAppAuth } from "@phala/cloud";

const result = await deployAppAuth({
  chain: kmsInfo.chain,
  kmsContractAddress: kmsInfo.kms_contract_address,
  privateKey: "0xabc123...",
  deviceId: provision.device_id,
  composeHash: provision.compose_hash,
  onTransactionSubmitted: (hash) => {
    console.log(`Transaction submitted: ${hash}`);
  },
});

console.log(`App ID: ${result.appId}`);
console.log(`Contract: ${result.appAuthAddress}`);
This function requires ETH on the target chain to pay for gas. The default minimum balance check is 0.001 ETH.

safeDeployAppAuth

Safe variant that returns a SafeResult<DeployAppAuth> instead of throwing on errors.