o1-labs / zkapp-cli

CLI to create a zkApp (zero-knowledge app) for Mina Protocol
https://docs.minaprotocol.com/zkapps/how-to-write-a-zkapp
Apache License 2.0
115 stars 43 forks source link
blockchain cryptocurrency mina web3 zero-knowledge

zkApp CLI

codecov

The zkApp CLI allows you to scaffold, write, test, and deploy zkApps (zero knowledge apps) for Mina Protocol using recommended best practices.

Apps are written using o1js, a TypeScript framework for writing zero knowledge proof-based smart contracts. o1js is automatically included when you create a project using the zkApp CLI.

Getting Started

Read through this README file and the Mina Protocol zkApp Developer docs.

Build foundational knowledge by completing the guided steps in the zkApp Developer Tutorials.

Get Involved

To learn about ways to participate and interact with community members, see the Mina Online Communities docs.

Contributions are always appreciated. See the zkApp CLI CONTRIBUTING guidelines.

Install the zkApp CLI

To install the zkApp CLI:

$ npm install -g zkapp-cli

To confirm successful installation:

$ zk --version

Update the zkApp CLI

You are prompted to install the new version if you are running an earlier zkApp CLI minor version. For example, if you are running version 0.9.8, but the current version is 0.10.2, you are prompted to update.

You are not prompted to update if you are using an earlier patch version. For example, you are not notified to upgrade when you are running 0.10.1, and the current version is 0.10.2.

To update to the latest version of the zkApp CLI:

$ npm update -g zkapp-cli

Dependencies

To use the zkApp CLI and o1js, your environment requires:

Use a package manager to install the required versions and upgrade older versions if needed. Package managers for the supported environments are:

To verify your installed versions, use npm -v, node -v, and git -v.

Usage

To see all of the zkApp CLI commands:

zk --help

Create a project

zk project my-proj  # or path/to/my-proj

✔ Fetch project template
✔ Initialize Git repo
✔ NPM install
✔ Set project name
✔ Git init commit

Success!

Next steps:
  cd my-proj
  git remote add origin <your-repo-url>
  git push -u origin main

This command creates a directory containing a new project template, fully set up and ready for local development.

Create an example project

zk example <name>

where name is one of the names found in the zkApps examples directory.

All examples are based on the standard project template created by the zkApp CLI and contain only changes within the src directory, so feel free to use one of these examples as your project base.

When inside an example folder in your terminal, you can run the example:

npm run build && node ./build/src/index.js

Create a new file

zk file <name>  # or path/to/name

This command creates name.js and name.test.js.

For convenience, when you run this command in your project's root directory creates the files inside your project's src dir automatically, even if you don't specify src/ as part of your file path.

When you run this command when you are not in your project's root dir, files are created at the path you specify relative to your terminal's current working directory.

Show system info

zk system

This command outputs system info such as your NodeJS version, NPM version, zkapp-cli version, and so on. For easier troubleshooting, be sure to include this information if submitting a bug report for zkapp-cli. See the CONTRIBUTING guidelines.

Update your config.json

zk config

The auto-generated config.json file contains your deployment-related configurations.

Run the zk config command to add a new deployment configuration to this file.

Respond to the interactive command prompts to build or update a deploy alias.

A deploy alias consists of:

Deploy your smart contract

zk deploy <alias>
// OR
zk deploy // shows a list of aliases in your project to choose from

After you run zk config, the zk deploy command allows you to deploy a smart contract to a specified deploy alias.

Note: When you deploy to an alias for the first time, you are prompted to choose which smart contract you want to deploy from those that exist as named exports in your project. The name of the smart contract that you choose is remembered by being saved into your config.json for this alias. For safety, the next time you run zk deploy <alias> this same smart contract automatically deploys to this alias. See Tutorial 3: Deploy to a Live Network.

Testing your zkApp

To test your zkApps, you first create automated tests for your smart contract and test with a simulated local blockchain. See Testing zkApps Locally.

Before you test with a live network, use Lightnet to test your zkApp locally on an accurate representation of a Mina blockchain.

zk lightnet --help

See Testing zkApps with Lightnet.

Block explorer

To launch a lightweight Mina explorer to monitor transactions in a web browser:

zk lightnet explorer

Community Support and Participation

Mina Protocol Discord is the most popular place where Mina enthusiasts and technical contributors gather to share knowledge.

Join us in these zkApps channels:

Feedback

To provide feedback, first review existing issues. You can create issues with feature requests for zkApp CLI and Lightnet in this repository.

zkApp CLI is an open source project, see the CONTRIBUTING guidelines.

License

Apache-2.0