Please note that zkApp programmability is not yet available on Mina Mainnet, but zkApps can now be deployed to Berkeley Testnet.
How to Write a zkApp
A zkApp consists of a smart contract and a UI to interact with it.
Write your smart contract using the Mina zkApp CLI.
First, install the Mina zkApp CLI.
The Mina zkApp CLI makes it easy to follow recommended best practices by providing project scaffolding including dependencies such as SnarkyJS, a test framework Jest, code auto-formatting Prettier, linting ES Lint, and more.
Install Mina zkApp CLI
npm install -g zkapp-cli
Dependencies:
- NodeJS 16+ (or 14 using
node --experimental-wasm-threads
) - NPM 6+
- Git 2+
If you have a later version installed, install the required version using the package manager for your system:
MacOs Homebrew
Windows Chocolatey
Linux (apt, yum, and others)
As recommended by the NodeJS Project, you might need to install a recent NodeJS version using NodeSource: Debian, rpm.
Start a project
Now that you have the Mina zkApp CLI installed, you can start with an example or start your own project.
Option A: Start with an example (recommended)
Examples are based on the standard project structure and provide additional files in the /src
directory.
Create the sudoku example project:
zk example sudoku
The created project includes the example files (the smart contract) in the project's
src/
directory.To see the files that were created, change to the
sudoku
directory and run thels
command or open the directory in a code editor, such as VS Code.Run tests and see the tests pass:
npm run test
To rerun tests automatically when you save changes to your code, run the tests in watch mode with
npm run testw
.Build the example:
npm run build
Compile your TypeScript into JavaScript in the project
/build
directory.Configure your zkApp:
zk config
The command prompts guide you in adding a network alias to your project
config.json
file.For Berkeley Testnet, use:
- name:
berkeley
- Mina GraphQL API URL:
https://proxy.berkeley.minaexplorer.com/graphql
- transaction fee:
0.1
Fund your fee payer account.
Follow the prompts to request tMina.
Deploy to Testnet:
zk deploy
Follow the prompts. For details, see how to deploy a zkApp.
Option B: Start your own project
Create your own project:
zk project <myproj>
The created project includes the files (the smart contract) in the project's
src/
directory.To see the files that were created, change to the project (whatever you called
<myproj>
) directory and run thels
command or open the directory in a code editor, such as VS Code.Run tests and see the tests pass:
npm run test
To rerun tests automatically when you save changes to your code, run the tests in watch mode with
npm run testw
.Build the example:
npm run build
Compile your TypeScript into JavaScript in the project
/build
directory.Configure your zkApp:
zk config
The command prompts guide you in adding a network alias to your project
config.json
file.For Berkeley Testnet, use:
- name:
berkeley
- Mina GraphQL API URL:
https://proxy.berkeley.minaexplorer.com/graphql
- transaction fee:
0.1
- name:
Fund your fee payer account.
Follow the prompts to request tMina.
Deploy to Testnet:
zk deploy
Follow the prompts. For details, see how to deploy a zkApp.
Writing your smart contract
zkApps are written in TypeScript using SnarkyJS. SnarkyJS is a TypeScript library for writing smart contracts based on zero-knowledge proofs for the Mina Protocol. It is included automatically when creating a new project using the Mina zkApp CLI.
See the SnarkyJS docs to learn more. The first 3 subsections are enough to get you started writing zkApps: T
Start with Tutorial 1: Hello World, a hands-on walkthrough that teaches you to create your first zkApp.
For a comprehensive documentation of the SnarkyJS API, please see the SnarkyJS reference.
Next Steps
Now that you've learned how to write and operate a basic smart contract, you can learn how to test your zkApp.