Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs/feat: zk lightnet #780

Merged
merged 25 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e9a3bb8
WIP draft of lightnet
barriebyron Dec 13, 2023
629d809
WIP for lightnet
barriebyron Dec 15, 2023
bb3d643
introduce lightnet, change local blockchain to simulated local blockc…
barriebyron Jan 4, 2024
ed2cc74
explainer page for Lightnet, w/ usage, overview, benefits
barriebyron Jan 5, 2024
b618126
clarify how we talk about the simulated local blockchain
barriebyron Jan 5, 2024
6dbb1f6
Merge branch 'main' into lightnet
barriebyron Jan 11, 2024
30bf5e0
rename testing pages and related link test, add redirects, update sid…
barriebyron Jan 19, 2024
8c1b0d1
moved how to test to a specific testing locally topic
barriebyron Jan 19, 2024
2979c43
explainer and how to Lightnet subcommands
barriebyron Jan 19, 2024
80542d2
Lightnet testing updates for terminology and high-level workflow
barriebyron Jan 19, 2024
6c0bab7
fix broken links after topic rename
barriebyron Jan 19, 2024
830a26d
integrate Lightnet into high level getting started
barriebyron Jan 24, 2024
f990c95
Merge branch 'main' into lightnet
barriebyron Jan 24, 2024
d07d979
get latest from main
barriebyron Jan 24, 2024
4345142
prerequisite versions fix and Lightnet work with Serhii
barriebyron Jan 24, 2024
6772dcb
improvements, edits, and suggestions from code review
barriebyron Jan 25, 2024
818c816
remove duplicate topic
barriebyron Jan 25, 2024
bd1de02
remove duplicate topic
barriebyron Jan 25, 2024
8eccce6
restore missing entries
barriebyron Jan 25, 2024
bee2346
review suggestions
barriebyron Jan 25, 2024
0ad4ad3
Merge branch 'main' into lightnet
barriebyron Jan 25, 2024
867ef4b
ready for next review round
barriebyron Jan 25, 2024
22805cb
:Merge branch 'lightnet' of github.com:o1-labs/docs2 into lightnet
barriebyron Jan 25, 2024
260bbb7
minor updates for style
barriebyron Jan 25, 2024
49a1511
rename link to match new file
barriebyron Jan 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading