zkApp programmability is not yet available on the Mina Mainnet, but zkApps can now be deployed on Berkeley Testnet.
Tutorial 3: Deploy to a Live Network
In previous tutorials, you learned how to deploy and run transactions on a local network.
In this tutorial, you use the
zk config command to create a deploy alias, request tMINA funds to pay for transaction fees, and deploy a project to a live network.
Mina zkApps are available only on feature-complete Berkeley, Mina's public Testnet. This tutorial reuses the
Square contract that you created in Tutorial 1: Hello World.
Ensure your environment meets the Prerequisites for zkApp Developer Tutorials.
If you have earlier versions of the zkApp CLI and o1js installed, be sure to Update the zkApp CLI to the latest version:
npm update -g zkapp-cli
Create a project
Create or change to a directory where you have write privileges.
Create a project by using the
$ zk project 03-deploying-to-a-live-network
zk projectcommand has the ability to scaffold the UI for your project. For this tutorial, select
? Create an accompanying UI project too? …
The expected output is:
✔ Create an accompanying UI project too? · none
✔ UI: Set up project
✔ Initialize Git repo
✔ Set up project
✔ NPM install
✔ NPM build contract
✔ Set project name
✔ Git init commit
git remote add origin <your-repo-url>
git push -u origin main
zk projectcommand creates the
Change into the
For this tutorial, you run commands from the root of the
03-deploying-to-a-live-network directory as you work in the
src directory on files that contain the TypeScript code for the smart contract.
Prepare the project
Start by deleting the default files that come with the new project.
Delete the default generated files:
$ rm src/Add.ts
$ rm src/Add.test.ts
$ rm src/interact.ts
Now, create a new file for your smart contract:
$ zk file src/Square
src/index.tsfiles from the example files for first tutorial 01-hello-world/src to your local
03-deploying-to-a-live-network/srcdirectory. If prompted, replace existing files.
Now that your smart contract is in place, you are ready to deploy your smart contract to Berkeley Testnet.
Mina zkApp CLI
You already installed the Mina zkApp CLI as part of the Prerequisites, so you have the tools to manage deployments.
In some cases, you might need to create a custom account for your zkApp, for example, to deploy a zkApp to a different key than the fee payer key, programmatically parameterize a zkApp before you initialize it, or create a smart contract programmatically for users as part of an application. For details, see Interacting with zkApps server-side.
Deploy the smart contract
config.json configuration file was automatically scaffolded when you created your project with the
zk project command. However, the generated configuration file does not yet contain the deploy alias.
zk config command prompts guide you to create a deploy alias in your project
You can have one or more deploy aliases for your project.
A deploy alias consists of:
A self-describing name (can be anything). Using naming patterns is helpful when you have more than one deploy alias.
The Mina GraphQL API URL that defines the network that receives your deploy transaction and broadcasts it to the appropriate Mina network (Testnet, Devnet, Mainnet, and so on)
The transaction fee (in MINA) to use when deploying
Two key pairs:
A key pair for the zkApp account. Public and private keys to use in your application are automatically generated in
A key pair to use as a fee payer account for updates and deployments. Public and private keys are stored on your local computer and can be used across multiple projects.
Fee payer account alias
- A fee payer account is required, you can choose to use an existing account or create a new fee payer account.
To configure your deployment, run the
zk configcommand and respond to the prompts:
$ zk config
For this tutorial on Berkeley Testnet, use:
Deploy alias name:
This tutorial uses
berkeley, but the deploy alias name can be anything and does not have to match the network name.
Mina GraphQL API URL:
Transaction fee to use when deploying (in MINA):
When prompted to choose an account to pay transaction fees, select
Create a new fee payer key pair:
Choose an account to pay transaction fees:
Create a new fee payer key pair
NOTE: The private key is created on this computer and is stored in plain text.
When prompted, give an alias to your new fee payer key pair. For this tutorial, use
Create an alias for this account: 03-deploy
Your key pairs and deploy alias are created:
✔ Create fee payer key pair at /Users/<username>/.cache/zkapp-cli/keys/03-deploy.json
✔ Create zkApp key pair at keys/berkeley.json
✔ Add deploy alias to config.json
- If this is a testnet, request tMINA at:
- To deploy, run: `zk deploy berkeley`
Request funds from the Testnet Faucet to fund your fee payer account.
Follow the prompts to request tMINA. For this tutorial, your MINA address is populated on the Testnet Faucet. tMINA arrives at your address when the next block is produced (~3 minutes).
To deploy your project:
$ zk deploy
At the interactive prompt, select the
? Which deploy alias would you like to deploy to? …
A verification key for your smart contract is generated (takes 10-30 seconds).
The deploy process is output:
✔ Build project
✔ Generate build.json
✔ Choose smart contract
Only one smart contract exists in the project: Square
Your config.json was updated to always use this
smart contract when deploying to this deploy alias.
✔ Generate verification key (takes 10-30 sec)
✔ Build transaction
Review and confirm the details of the transaction:
✖ Confirm to send transaction
│ Deploy Alias │ berkeley │
│ Fee-Payer Alias │ 03-deploy │
│ URL │ https://proxy.berkeley.minaexplorer.com/graphql │
│ Smart Contract │ Square │
When prompted, type
yesto confirm and send the transaction.
✔ Send to network
Success! Deploy transaction sent.
Your smart contract will be live (or updated)
as soon as the transaction is included in a block:
To see the zkApp transaction, go to
<txn-hash>is the transaction hash that is output to your terminal.
- The zkApp Pending Transaction shows until the transaction is included in the next block.
- The zkApp Transaction shows after the transaction is included in a block.
After the transaction is included in a block, your smart contract is deployed!
- The Mina account at this public key now contains the verification key associated with this smart contract.
You ran the
zk config command to:
- Create a deploy alias
- Create a fee payer key pair at
- Create a zkApp key pair at
You requested tMINA to fund your deploy transactions. Use the remaining tMINA to keep building and testing.
You ran the
zk deploy command to:
- Generate a verification key for your smart contract
- Add the deploy alias to the project
About the Smart Contract Transactions
Because this tutorial used the smart contract for Tutorial 1: Hello World, the smart contract
editState permissions require that a transaction must contain a valid zk proof that was created by the private key associated with this zkApp account.
- When a user interacts with this smart contract by providing a proof, the proof is generated locally on the user's device and included in a transaction.
- When the transaction is submitted to the network, the proof is checked to ensure it is correct and matches the on-chain verification key.
- After the transaction is accepted, the proof and transaction are recursively proved and bundled into Mina's recursive zero knowledge proof.
When you change the smart contract code, the associated verification key also changes. Use the same steps to redeploy the smart contract.
For a typical smart contract, permissions are set to allow only proof authorization: the proof in zero knowledge proof. You learn more about setting permissions in a later tutorial.
Watch this tutorial for a step-by-step guide and extra explanations on how to deploy a zkApp.
The video is provided for educational purposes and uses earlier versions of the zkApp CLI and o1js, so there are some differences. This tutorial is tested with a specific version of the zkApp CLI and o1js.
Congratulations! You have successfully deployed a smart contract to a live network.
Check out Tutorial 4: Build a zkApp UI in the Browser with React to implement a browser UI that interacts with a smart contract.