Deployment Guide
Deployment works the same way for ZkApps on Mina, Devnet, and Zeko. All Smart Contracts have a deploy()
method that must be called to create the account on chain. The example code below shows an example of how to properly configure a Mina network and generate a deploy transaction.
Deploying a ZkApp on Mina implies creating a brand new account on chain. That means that you need to generate a private key for the account, and pay an account creation fee, just like any other account. The private key that you generate will have some default permissions (review the Permissions documentation for a refresher). Any permissions that are controlled by a signature will be possible to control by the private key holder of the Smart Contract. However, if you deploy a Smart Contract with proof permissions for every operation, then the private key will not be able to perform those operations.
Currently, the only exception is the setVerificationKey
permission, which can only be set to impossibleDuringCurrentVersion()
, because in the event of a proof system upgrade to the entire chain, a smart contract will not be able to produce valid proofs until it is upgraded to the new proof system.
Network Configuration
Configure your deployment target with the appropriate network:
export const NetworkConfig = {
// Mina Mainnet configuration
mainnet: {
mina: "https://api.minascan.io/node/mainnet/v1/graphql",
archive: "https://api.minascan.io/archive/mainnet/v1/graphql",
name: "mainnet",
networkId: "mainnet",
},
// Mina Devnet configuration
devnet: {
mina: "https://api.minascan.io/node/devnet/v1/graphql",
archive: "https://api.minascan.io/archive/devnet/v1/graphql",
name: "devnet",
networkId: "testnet",
},
// Zeko configuration
zeko_testnet: {
mina: "https://devnet.zeko.io/graphql",
archive: "https://devnet.zeko.io/graphql", // Zeko uses same endpoint for both
name: "zeko testnet",
networkId: "testnet",
},
};
Deploying a ZkApp
Here's how to deploy a zkApp to any network:
export async function deployToDevnet(
contractClass: typeof SmartContract, // In practice, use your specific contract class here
contractPrivateKey: PrivateKey,
deployerPrivateKey: PrivateKey
) {
console.log("Configuring Mina instance for devnet...");
const Network = Mina.Network({
mina: NetworkConfig.devnet.mina,
archive: NetworkConfig.devnet.archive,
});
Mina.setActiveInstance(Network);
const deployerPublicKey = deployerPrivateKey.toPublicKey();
const contractPublicKey = contractPrivateKey.toPublicKey();
console.log("Deployer address:", deployerPublicKey.toBase58());
console.log("Contract address:", contractPublicKey.toBase58());
// Check/fund account using faucet if needed
try {
await fetchAccount({ publicKey: deployerPublicKey });
const deployerAccount = Mina.getAccount(deployerPublicKey);
console.log(
"Deployer balance:",
deployerAccount.balance.toBigInt().toString()
);
if (deployerAccount.balance.lessThan(UInt64.from(1_000_000_000))) {
console.log(
"Low balance detected, Please visit https://faucet.minaprotocol.com to fund your account..."
);
}
} catch (error) {
console.log("Account not found, please fund it using the faucet");
console.log("Faucet URL: https://faucet.minaprotocol.com");
throw error;
}
// Compile contract
console.log("Compiling contract...");
const { verificationKey } = await contractClass.compile();
const contract = new contractClass(contractPublicKey);
// Create deployment transaction
console.log("Creating deployment transaction...");
const deployTx = await Mina.transaction(
{
sender: deployerPublicKey,
fee: 100_000_000, // 0.1 MINA fee
memo: "zkApp deployment to devnet",
},
async () => {
AccountUpdate.fundNewAccount(deployerPublicKey);
contract.deploy({ verificationKey });
}
);
await deployTx.prove();
const signedTx = deployTx.sign([deployerPrivateKey, contractPrivateKey]);
console.log("Sending transaction to devnet...");
const txResult = await signedTx.send();
console.log("Devnet deployment successful!");
console.log("Transaction hash:", txResult.hash);
return {
contractAddress: contractPublicKey.toBase58(),
transactionHash: txResult.hash,
network: "devnet",
};
}
Network Comparison
Network | Purpose | Tokens | Transaction Inclusion |
---|---|---|---|
Mainnet | Production L1 | Real MINA | ~3-5 min |
Devnet | Testing L1 | Test MINA | ~5-10 min |
Zeko Testnet | Testing L2 | Test MINA | ~10 sec |
API Reference
For detailed deployment information, see: