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

📝 Adding Steps for 09-recurssion tutorial #763

Closed
wants to merge 3 commits into from

Conversation

LuffySama-Dev
Copy link
Contributor

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 😄

@LuffySama-Dev LuffySama-Dev requested a review from a team as a code owner November 28, 2023 14:48
Copy link

vercel bot commented Nov 28, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 28, 2023 4:32pm

Copy link

vercel bot commented Nov 28, 2023

@LuffySama-Dev is attempting to deploy a commit to the o1labs Team on Vercel.

A member of the Team first needs to authorize it.

@LuffySama-Dev
Copy link
Contributor Author

Hi @barriebyron ,

Changes made:

  • Tutorial made easy to follow
  • Using latest o1js version
  • Match the file structure and code base to tutorial
  • Changes made in example are tested locally

Upcoming changes:

  • - Updating tutorial for rollup.ts example
  • - Updating tutorial for vote.ts example
  • - Updating the file structure and code according to upcoming changes in tutorial

Issues being resolve here are :

Thank You 😄


To create a ZkProgram, start with the `init()` method.
:::info
Copy link
Contributor

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

Comment on lines +88 to +111
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!
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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`.

Copy link
Contributor

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

Comment on lines +113 to +119
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Comment on lines +121 to +146
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.
Copy link
Contributor

@barriebyron barriebyron Nov 29, 2023

Choose a reason for hiding this comment

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

Suggested change
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.

Comment on lines +152 to +171
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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Contributor

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

Comment on lines +172 to +180
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Contributor

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?

Copy link
Contributor

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!

Copy link
Contributor Author

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 😃

Comment on lines +188 to +192
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 link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Contributor

@barriebyron barriebyron Nov 29, 2023

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

Comment on lines +194 to +198
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.
Copy link
Contributor

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.
Copy link
Contributor

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:
Copy link
Contributor

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

Comment on lines +302 to +304
### Call Methods

Now we will add methods to call ZkProgram:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
### Call Methods
Now we will add methods to call ZkProgram:
### Call Methods
Add methods to call ZkProgram:


```typescript
console.log('compiling...');
3
Copy link
Contributor

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.
Copy link
Contributor

@barriebyron barriebyron Nov 29, 2023

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

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@LuffySama-Dev LuffySama-Dev Jan 16, 2024

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 😃

Copy link
Contributor Author

@LuffySama-Dev LuffySama-Dev Jan 16, 2024

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';
Copy link
Contributor

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?

Copy link
Contributor Author

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:

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@barriebyron
Copy link
Contributor

barriebyron commented Nov 29, 2023

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!

@barriebyron barriebyron marked this pull request as draft November 29, 2023 17:42
@LuffySama-Dev
Copy link
Contributor Author

Hi @barriebyron ,

Sure, I would love to make those changes.
If possible can you please assign them to me to so I can keep track of them ?

Thank You 😊

@barriebyron
Copy link
Contributor

@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?

@LuffySama-Dev
Copy link
Contributor Author

Hi @barriebyron ,

I thought above mentioned changes were related to different issue and got confused and asked to assign.
Now that these are all related to this not required.

Thank You 😃

@LuffySama-Dev
Copy link
Contributor Author

Hi @barriebyron ,

Hope you are doing great!!
I want to commit these changes but the problem is that if I make this changes then #786 will break.
So, once it is merged I will update this one accordingly also, will remove the isReady and shutdown from the example files and test and commit them.

Thanks Luffy 😃

@LuffySama-Dev
Copy link
Contributor Author

Hi @barriebyron ,

I am closing this PR as new PR is raised for this #796

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants