-
Notifications
You must be signed in to change notification settings - Fork 145
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
📝 Adding Steps for 09-recurssion tutorial #763
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@LuffySama-Dev is attempting to deploy a commit to the o1labs Team on Vercel. A member of the Team first needs to authorize it. |
…actoring to match tutorial
Hi @barriebyron , Changes made:
Upcoming changes:
Issues being resolve here are :
Thank You 😄 |
|
||
To create a ZkProgram, start with the `init()` method. | ||
:::info |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LuffySama-Dev we are removing line numbers for future, so we can omit this part
The `zk project` command has the ability to scaffold the UI for your project. For this tutorial, select `none`: | ||
|
||
``` | ||
? Create an accompanying UI project too? … | ||
next | ||
svelte | ||
nuxt | ||
empty | ||
❯ none | ||
``` | ||
|
||
The expected output is: | ||
|
||
```sh | ||
✔ 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 | ||
|
||
Success! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The `zk project` command has the ability to scaffold the UI for your project. For this tutorial, select `none`: | |
``` | |
? Create an accompanying UI project too? … | |
next | |
svelte | |
nuxt | |
empty | |
❯ none | |
``` | |
The expected output is: | |
```sh | |
✔ 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 | |
Success! | |
The `zk project` command has the ability to scaffold the UI for your project. For this tutorial, select `none`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is tutorial 9, we can leave out the very detailed steps since devs will have already mastered these steps in earlier tutorials
Next steps: | ||
cd 09-recursion | ||
git remote add origin <your-repo-url> | ||
git push -u origin main | ||
``` | ||
|
||
The `zk project` command creates the `09-recursion` directory that contains the scaffolding for your project, including tools such as the Prettier code formatting tool, the ESLint static code analysis tool, and the Jest JavaScript testing framework. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next steps: | |
cd 09-recursion | |
git remote add origin <your-repo-url> | |
git push -u origin main | |
``` | |
The `zk project` command creates the `09-recursion` directory that contains the scaffolding for your project, including tools such as the Prettier code formatting tool, the ESLint static code analysis tool, and the Jest JavaScript testing framework. | |
As you learned in earlier tutorials, the `zk project` command creates the `09-recursion` directory that contains the scaffolding for your project. |
1. Change into the `09-recursion` directory and list the contents: | ||
|
||
```sh | ||
$ cd 09-recursion | ||
$ ls | ||
``` | ||
|
||
The output shows these results: | ||
|
||
```sh | ||
LICENSE | ||
README.md | ||
babel.config.cjs | ||
build | ||
config.json | ||
jest-resolver.cjs | ||
jest.config.js | ||
keys | ||
node_modules | ||
package-lock.json | ||
package.json | ||
src | ||
tsconfig.json | ||
``` | ||
|
||
For this tutorial, you run commands from the root of the `09-recursion` directory as you work in the `src` directory on files that contain the TypeScript code for the smart contract. Each time you make updates, then build or deploy, the TypeScript code is compiled into JavaScript in the `build` directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Change into the `09-recursion` directory and list the contents: | |
```sh | |
$ cd 09-recursion | |
$ ls | |
``` | |
The output shows these results: | |
```sh | |
LICENSE | |
README.md | |
babel.config.cjs | |
build | |
config.json | |
jest-resolver.cjs | |
jest.config.js | |
keys | |
node_modules | |
package-lock.json | |
package.json | |
src | |
tsconfig.json | |
``` | |
For this tutorial, you run commands from the root of the `09-recursion` directory as you work in the `src` directory on files that contain the TypeScript code for the smart contract. Each time you make updates, then build or deploy, the TypeScript code is compiled into JavaScript in the `build` directory. | |
1. Change into the `09-recursion` directory. Like all projects, you run commands from the root of the `09-recursion` directory as you work in the `src` directory on files that contain the TypeScript code for the smart contract. Each time you make updates, then build or deploy, the TypeScript code is compiled into JavaScript in the `build` directory. |
|
||
### Prepare the project | ||
|
||
Start by deleting the default files that come with the new project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Start by deleting the default files that come with the new project. | |
Like earlier tutorials, you can prepare your project by deleting the default files that come with the new project and creating new files. |
1. To delete the old files: | ||
|
||
```sh | ||
$ rm src/Add.ts | ||
$ rm src/Add.test.ts | ||
$ rm src/interact.ts | ||
``` | ||
|
||
1. Now, create the new files for your project: | ||
|
||
```sh | ||
$ zk file src/Add | ||
$ touch src/main.ts | ||
``` | ||
|
||
- The `zk file` command created the `src/Add.ts` and `src/Add.test.ts` test files. | ||
- However, this tutorial does not include writing tests, so you just use the `main.ts` file as a script to interact with the smart contract and observe how it works. | ||
|
||
In later tutorials, you learn how to interact with a smart contract from the browser, like a typical end user. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. To delete the old files: | |
```sh | |
$ rm src/Add.ts | |
$ rm src/Add.test.ts | |
$ rm src/interact.ts | |
``` | |
1. Now, create the new files for your project: | |
```sh | |
$ zk file src/Add | |
$ touch src/main.ts | |
``` | |
- The `zk file` command created the `src/Add.ts` and `src/Add.test.ts` test files. | |
- However, this tutorial does not include writing tests, so you just use the `main.ts` file as a script to interact with the smart contract and observe how it works. | |
In later tutorials, you learn how to interact with a smart contract from the browser, like a typical end user. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll omit these steps since devs will already have experience
3. Now, open `src/index.ts` in a text editor and change it to look like: | ||
|
||
```ts src/index.ts | ||
1 import { Add } from './Add.js'; | ||
2 | ||
3 export { Add }; | ||
``` | ||
|
||
The `src/index.ts` file contains all of the exports you want to make available for consumption from outside your smart contract project, such as from a UI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3. Now, open `src/index.ts` in a text editor and change it to look like: | |
```ts src/index.ts | |
1 import { Add } from './Add.js'; | |
2 | |
3 export { Add }; | |
``` | |
The `src/index.ts` file contains all of the exports you want to make available for consumption from outside your smart contract project, such as from a UI. | |
Open `src/index.ts` in a text editor and import the Add smart contract, like: | |
```ts src/index.ts | |
import { Add } from './Add.js'; | |
export { Add }; |
The src/index.ts
file contains all of the exports you want to make available for consumption from outside your smart contract project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be sure the contract example file and all references align
|
||
Now, the fun part! Write your smart contract in the `src/Add.ts` file. | ||
|
||
Line numbers are provided for convenience. A final version of the smart contract is provided in the [Add.ts](https://github.com/o1-labs/docs2/blob/main/examples/zkapps/01-hello-world/src/Add.ts) example file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line numbers are provided for convenience. A final version of the smart contract is provided in the [Add.ts](https://github.com/o1-labs/docs2/blob/main/examples/zkapps/01-hello-world/src/Add.ts) example file. | |
A final version of the smart contract is provided in the [Add.ts](https://github.com/o1-labs/docs2/blob/main/examples/zkapps/01-hello-world/src/Add.ts) example file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you help me understand why we need the Add.ts file from tutorial 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll see my earlier questions, all related. Thank you for this work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @barriebyron ,
I wen through the existing tutorial and found that we are actually showing recursion example for the Addition. In the current tutorial and it's example we are using main.ts
as our main file and all the code it.
Now in earlier tutorials if you will see we were following pattern like there is a SmartContractfiles.ts
which contains the smartcontract code and main.ts
which includes code to interact with the SmarContractfile.ts
.
This tutorial doesn't seem to be following this and might cause confusion for the developer. To avoid whole confusion I am trying to bring everything in the same pattern.
For example : In this tutorial itself you can see the Vote smartcontract has file name Vote.ts
and same for Rollup smartcontract i.e Rollup.ts
.
So, I am naming the Add smartcontract file as Add.ts
for ease of understanding.
And coming to the file from tutorial 1, I did not review which tutorial it was taking file from. It does not have anything to do with tutorial 1.
I will fix this and update it in my upcoming commits.
Thanks Luffy 😃
This part of the tutorial walks you through the Add ZkProgram code already completed in the `src/Add.ts` example file. | ||
|
||
### Copy the example | ||
|
||
This tutorial describes each part of the completed code in the [Add.ts](https://github.com/o1-labs/docs2/blob/main/examples/zkapps/01-hello-world/src/Add.ts) example file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of the tutorial walks you through the Add ZkProgram code already completed in the `src/Add.ts` example file. | |
### Copy the example | |
This tutorial describes each part of the completed code in the [Add.ts](https://github.com/o1-labs/docs2/blob/main/examples/zkapps/01-hello-world/src/Add.ts) example file. | |
### Copy the example | |
Use the Add code already completed in the [Add.ts](https://github.com/o1-labs/docs2/blob/main/examples/zkapps/01-hello-world/src/Add.ts) example file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can verify all example files and doc references are in sync for https://github.com/o1-labs/docs2/tree/main/examples/zkapps/09-recursion/src directory
1. First, open the [Add.ts](https://github.com/o1-labs/docs2/blob/main/examples/zkapps/01-hello-world/src/Add.ts) example file. | ||
|
||
1. Copy the entire contents of the file into your ZkProgram in the `src/Add.ts` file. | ||
|
||
Now you are ready to review the imports in the ZkProgram. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. First, open the [Add.ts](https://github.com/o1-labs/docs2/blob/main/examples/zkapps/01-hello-world/src/Add.ts) example file. | |
1. Copy the entire contents of the file into your ZkProgram in the `src/Add.ts` file. | |
Now you are ready to review the imports in the ZkProgram. | |
1. First, open the [Add.ts](https://github.com/o1-labs/docs2/blob/main/examples/zkapps/01-hello-world/src/Add.ts) example file. | |
1. Copy the file's entire contents into your project `src/Add.ts` file. | |
- For each method, declare the inputs it will receive. | ||
- The first argument of a ZkProgram method is always the state of the ZkProgram, named `publicInput` since it is public. | ||
|
||
```typescript |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's remove the line numbers, easiest to copy code right from the example file
newState.assertEquals(earlierProof.publicInput.add(numberToAdd)); | ||
}, | ||
}, | ||
15 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove line numbers here too
newState.assertEquals(earlierProof1.publicInput.add(earlierProof2.publicInput)); | ||
}, | ||
}, | ||
28 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove line numbers here too
:::info | ||
|
||
```ts src/Add.ts | ||
1 import { Field, SelfProof, ZkProgram } from 'o1js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 import { Field, SelfProof, ZkProgram } from 'o1js'; | |
import { Field, SelfProof, ZkProgram } from 'o1js'; |
|
||
These items are: | ||
|
||
- `Field`: The native number type in o1js. You can think of Field elements as unsigned integers. Field elements are the most basic type in o1js. All other o1js-compatible types are built on top of Field elements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you want to describe SelfProof?
To use ZkProgram, compile it and then call methods on it: | ||
## Interact with a smart contract | ||
|
||
Next, write a script that interacts with your smart contract. As before, the complete [main.ts](https://github.com/o1-labs/docs2/blob/main/examples/zkapps/01-hello-world/src/main.ts) example file is provided. Follow these steps to build the `main.ts` file so you can interact with the smart contract. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since Tutorial 4 was the "model" for these updates, it talks about interacting with the smart contract. We can omit the UI-based steps here
|
||
For this tutorial, the `import` statement brings in items from `o1js` that you use to interact with your smart contract. | ||
|
||
1. Copy the following lines from [main.ts](https://github.com/o1-labs/docs2/blob/main/examples/zkapps/01-hello-world/src/main.ts) example file into the `src/main.ts` file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to interact with UI (I don't think so) you can omit the interact steps
### Call Methods | ||
|
||
Now we will add methods to call ZkProgram: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Call Methods | |
Now we will add methods to call ZkProgram: | |
### Call Methods | |
Add methods to call ZkProgram: |
|
||
```typescript | ||
console.log('compiling...'); | ||
3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be sure the example code in https://github.com/o1-labs/docs2/blob/main/examples/zkapps/09-recursion/src/main.ts is current
and match here (omit line numbers please)
|
||
const proof0 = await Add.init(Field(0)); | ||
Now that the Square smart contract is complete, these commands run your project as a local blockchain. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the contract we want to build? Square? (be sure all the file names and example files match up throughout)
https://github.com/o1-labs/docs2/blob/main/examples/zkapps/09-recursion/src/Square.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh Sorry, I missed this one.
Will proof read it once again.
According to existing tutorial and the examples, we are building three files mainly:
- Add.ts
- Rollup.ts
- Vote.ts
1. Now, create the new files for your project: | ||
|
||
```sh | ||
$ zk file src/Add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you want to use Square.ts? https://github.com/o1-labs/docs2/blob/main/examples/zkapps/09-recursion/src/Square.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @barriebyron ,
I went through all the files and I am not sure why Square.ts
is used here. Code inside this file does not aligns to what tutorial is actually for.
According to me we can remove it, if possible can we ask someone from team to review it ?
Same is for zkProgram_wrapper.ts
.
Can you please help to get it reviewed so I can remove it in coming commits ?
Thanks Luffy 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About Add.ts
I will change it back to main.ts
same as previous one.
3. Now, open `src/index.ts` in a text editor and change it to look like: | ||
|
||
```ts src/index.ts | ||
1 import { Add } from './Add.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure where we're going with this step, are you replacing https://github.com/o1-labs/docs2/blob/main/examples/zkapps/09-recursion/src/Square.ts with Add.ts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, actually Square.ts
was never used in tutorial. The fils which was used is main.ts
. The code which we are explaining in this tutorial is about recursion and it matches the code from main.ts
and not the Square.ts
.
|
||
console.log('making proof 1') | ||
To compile the TypeScript code into JavaScript: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested this yet... looks like you ran the code locally, thank you!
would you be up for fixing the README.md file to be accurate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes Sure,
I will do it.
can you also do the code updates that require removing isReady and shutdown from the example files (and test):
Just to let you know, I'm a technical writer, not a developer... so I'll follow your steps and test the code, and we'll get an o1js developer to review the final. For now, I've moved this PR to draft status while changes are made. Thank you! |
Hi @barriebyron , Sure, I would love to make those changes. Thank You 😊 |
@LuffySama-Dev can you help me understand "please assign them to me" request? You can make all changes in this PR without new issues, or are you asking for new issues to track? |
Hi @barriebyron , I thought above mentioned changes were related to different issue and got confused and asked to assign. Thank You 😃 |
Hi @barriebyron , Hope you are doing great!! Thanks Luffy 😃 |
Hi @barriebyron , I am closing this PR as new PR is raised for this #796 Thank you |
Hi @barriebyron ,
So, I am working on your suggestion and this what I have done till now.
I hope this is what you are expecting.
This might have certain problem but we can work and resolve them together 🙌.
Thank You 😄