Skip to content

Commit

Permalink
Merge pull request #780 from o1-labs/lightnet
Browse files Browse the repository at this point in the history
docs/feat: zk lightnet
  • Loading branch information
barriebyron authored Jan 25, 2024
2 parents 32ee868 + 49a1511 commit eda1fbd
Show file tree
Hide file tree
Showing 11 changed files with 374 additions and 56 deletions.
63 changes: 52 additions & 11 deletions docs/zkapps/getting-started-zkapps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords:
- zkapps
- mina protocol
- smart contracts
- zero-knowledge proofs
- zero knowledge proofs
- off-chain execution
- typescript
- quickstart zkapps
Expand All @@ -21,7 +21,7 @@ zkApp programmability is not yet available on the Mina Mainnet. You can get star

# zkApps Getting Started

You can start writing zkApps with just a few steps. You can write zkApps for your project in other ways, this Getting Started Guide provides a high-level workflow to build and deploy quickly.
You can start writing zkApps with just a few steps. The focus of this Getting Started Guide is a high-level workflow to build and deploy quickly.

## High-Level Workflow

Expand All @@ -30,7 +30,9 @@ You can start writing zkApps with just a few steps. You can write zkApps for you
1. [Add testing code](#3-add-testing-code)
1. [Add functionality](#4-add-functionality)
1. [Create an integration test](#5-create-an-integration-test)
1. [Test with a live network](#6-test-with-a-live-network)
1. [Test locally](#6-test-with-local-simulated-blockchain)
1. [Test with Lightnet](#7-test-with-lightnet)
1. [Test with a live network](#8-test-with-a-live-network)

### 1. Install or update the zkApp CLI

Expand Down Expand Up @@ -66,14 +68,14 @@ When you use the zkApp CLI to create a project, tests and examples are included.

1. See the `import` statements in the [Add.test.ts](https://github.com/o1-labs/zkapp-cli/blob/main/templates/project-ts/src/Add.test.ts#L1-L2) example file.

1. A `LocalBlockchain` instance to interact with is included in the [Add.test.ts](https://github.com/o1-labs/zkapp-cli/blob/main/templates/project-ts/src/Add.test.ts#L27-L28) example file.
1. A simulated `LocalBlockchain` instance you can interact with is included in the [Add.test.ts](https://github.com/o1-labs/zkapp-cli/blob/main/templates/project-ts/src/Add.test.ts#L27-L28) example file.

1. In o1js, an array of 10 test accounts to pay fees and sign transactions are provided for the `LocalBlockchain` instance. These can be accessed with `Local.testAccounts` as shown in the [Add.test.ts](https://github.com/o1-labs/zkapp-cli/blob/main/templates/project-ts/src/Add.test.ts#L29-L31) example file. The example uses the public/private key pairs of two of these accounts. The example uses these names, but the names can be anything:
1. In o1js, an array of 10 test accounts to pay fees and sign transactions are provided for the simulated `LocalBlockchain` instance. These can be accessed with `Local.testAccounts` as shown in the [Add.test.ts](https://github.com/o1-labs/zkapp-cli/blob/main/templates/project-ts/src/Add.test.ts#L29-L31) example file. The example uses the public/private key pairs of two of these accounts. The example uses these names, but the names can be anything:

- `deployerAccount` deploys the smart contract
- `senderAccount` pays transaction fees

1. Deploy the smart contract to the `LocalBlockchain` instance that simulates a network for testing purposes.
1. Deploy the smart contract to the simulated `LocalBlockchain` instance that simulates a network for testing purposes.

See the `localDeploy` function in the [Add.test.ts](https://github.com/o1-labs/zkapp-cli/blob/main/templates/project-ts/src/Add.test.ts#L38-L46) example file.

Expand All @@ -98,13 +100,52 @@ Add the logic for your smart contract.
- If it works as expected with no errors, add more functionality.
- If there are errors, look through the stack traces to find the source of the errors and update the contract to resolve them.

### 5. Create an integration test.
### 5. Create integration test

- Create a Node.js script to run the smart contract and test it's functionality, similar to step [3. Add testing code](#3-add-testing-code).

For an example, see the Node.js script that runs the Tic Tac Toe smart contract in the [run.ts](https://github.com/o1-labs/zkapp-cli/blob/main/examples/tictactoe/ts/src/run.ts) file.

### 6. Test with a live network
### 6. Test locally

- [Test zkApps locally](/zkapps/testing-zkapps-locally) with a simulated local blockchain.

### 7. Test with Lightnet

- Use [Lightnet](/zkapps/testing-zkapps-lightnet) to test your zkApp with an accurate representation of Mina blockchain.

1. Start Lightnet:

```sh
zk lightnet start
```

The default settings start a single node that successfully serves the majority of testing requirements.

1. Verify the status of the local blockchain:

```sh
zk lightnet status
```

1. Communicate with the Mina Accounts-Manager service to fetch account details.

- Mina Accounts-Manager is deployed to http://localhost:8181/
- Use HTTP endpoints to acquire, release, list, lock, and unlock accounts

1. Configure your zkApp for Lightnet blockchain. Use the endpoints provided by the `zk lightnet status` command.

- Deploy name
- Set the Mina GraphQL API URL to deploy to: http://localhost:8080/graphql
- Set transaction fee to use when deploying (in MINA): 0.1

1. Deploy your zkApp to Lightnet:

```sh
zk deploy
```

### 8. Test with a live network

To deploy the smart contract to the Testnet, run the `zk` commands from the directory that contains your smart contract.

Expand All @@ -116,7 +157,7 @@ To deploy the smart contract to the Testnet, run the `zk` commands from the dire

Follow the prompts to specify a deploy alias name (can be anything), URL to deploy to, fee (in MINA) to be used when sending your deploy transaction, and the fee payer account.

For the Berkeley Testnet, use: <!-- or whatever the ITN is called, let's give that specific information -->
For the Berkeley Testnet, use:

- Deploy alias name: `berkeley`

Expand Down Expand Up @@ -184,7 +225,7 @@ To deploy the smart contract to the Testnet, run the `zk` commands from the dire
node build/src/interact.js
```

1. Keep building and experimenting! After you add features to your contract, repeat [7. Test with a live network](#6-test-with-a-live-network) to test with a live network.
1. Keep building and experimenting! After you add features to your contract, repeat [7. Test with a live network](#7-test-with-a-live-network) to test with a live network.

## Learn more

Expand All @@ -194,4 +235,4 @@ Try the [zkApp Developer Tutorials](/zkapps/tutorials) for use cases that guide

## Get help and join the community

Join the [#zkapps-developers](https://discord.com/channels/484437221055922177/915745847692636181) channel on Mina Protocol Discord.
Join the [#zkapps-developers](https://discord.com/channels/484437221055922177/915745847692636181) channel on Mina Protocol Discord.
2 changes: 1 addition & 1 deletion docs/zkapps/how-to-write-a-zkapp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,4 @@ For comprehensive details about the o1js API, see the [o1js reference](o1js-refe

## Next Steps

Now that you've learned how to write and operate a basic smart contract, you can learn [how to test your zkApp](how-to-test-a-zkapp).
Now that you've learned how to write and operate a basic smart contract, you can learn about [Testing zkApps Locally](/zkapps/testing-zkapps-locally).
6 changes: 3 additions & 3 deletions docs/zkapps/install-zkapp-cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ To build zero knowledge apps that use [o1js](/zkapps/o1js), you only need to ins

### Dependencies

- NodeJS v16 and later
- NPM v8 and later
- Git 2+
- NodeJS v18 and later
- NPM v10 and later
- git v2 and later

If you have a later version of a dependency, install the required version using the package manager for your system:

Expand Down
2 changes: 1 addition & 1 deletion docs/zkapps/o1js/actions-and-reducer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ In the near future, we want to add a function to retrieve actions from an archiv
this.reducer.getActions({ fromActionState?: Field, endActionState?: Field }): A[][];
```

Right now, `getActions` is available for [testing with `LocalBlockchain`](/zkapps/how-to-test-a-zkapp).
Use `getActions` for testing with a simulated `LocalBlockchain`. See [Testing zkApps Locally](/zkapps/testing-zkapps-locally).

### Actions for concurrent state updates

Expand Down
8 changes: 4 additions & 4 deletions docs/zkapps/o1js/interact-with-mina.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,15 @@ await pendingTx.wait();
// our account updates are applied on chain!
```

In addition to `Mina.Metwork`, you can also use a mocked "Mina instance" for local testing:
In addition to `Mina.Network`, you can also use a simulated local blockchain for local testing:

```ts
const Local = Mina.LocalBlockchain();
Mina.setActiveInstance(Local);
```

Doing this means setting up a fresh, local ledger that is pre-filled with a couple of accounts with funds that you have access to. "Sending" a transaction here just means applying your account updates to that local Mina instance. This is helpful for testing, especially because account updates go through the same validation logic locally that they would on-chain.
Doing this means setting up a fresh, local ledger that is pre-filled with a couple of accounts with funds that you have access to. "Sending" a transaction here just means applying your account updates to that local simulated Mina instance. This is helpful for testing, especially because account updates go through the same validation logic locally that they would on-chain.

Fun fact: The `LocalBlockchain` instance literally uses the same OCaml code for transaction validation and application that the Mina node uses; it's compiled to JS with [js_of_ocaml](https://github.com/ocsigen/js_of_ocaml).
Fun fact: The `LocalBlockchain` instance literally uses the same OCaml code for transaction validation and application that the Mina node uses; it's compiled to JavaScript with [js_of_ocaml](https://github.com/ocsigen/js_of_ocaml).

You can learn more about testing in [How to test your zkApp](/zkapps/how-to-test-a-zkapp).
You can learn more about testing in [Test zkApps Locally](/zkapps/testing-zkapps-locally).
Loading

1 comment on commit eda1fbd

@vercel
Copy link

@vercel vercel bot commented on eda1fbd Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs2 – ./

docs2-git-main-minadocs.vercel.app
docs2-minadocs.vercel.app
docs.minaprotocol.com

Please sign in to comment.