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

Update code, tutorials, and code snippets to be compatible with async circuits #886

Merged
merged 92 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
2871400
feat(Square.ts): make the update @method async
ymekuria Mar 12, 2024
0a3f7d1
feat(main.ts): add async/await to deploy transaction and contract call
ymekuria Mar 12, 2024
d25a625
feat(main.ts): add async/await to update transaction and contract call
ymekuria Mar 12, 2024
68a72d2
feat(main.ts): add async/await to update to 75 and 81 transaction and…
ymekuria Mar 12, 2024
72b995a
feat(IncrementSecret.ts): add async to initState @method
ymekuria Mar 13, 2024
03e338f
feat(IncrementSecret.ts): make the incrementSecret @method async
ymekuria Mar 13, 2024
95bd891
feat(main.ts): add async/await to transaction blocks and contract calls
ymekuria Mar 13, 2024
d93f570
feat(Add.test.ts): add async/await to transaction blocks and contract…
ymekuria Mar 13, 2024
0bdf570
feat(Add.ts): make update @method async
ymekuria Mar 13, 2024
ea88bea
feat(interact.ts): add async/await to transaction block and update co…
ymekuria Mar 13, 2024
df3af61
feat(interact.ts): update to support networkId config and pending tra…
ymekuria Mar 13, 2024
9254d05
feat(interact.ts): update to support networkId config and pending tra…
ymekuria Mar 13, 2024
2df85eb
feat(BasicMerkleTreeContract.ts): make initState @method async
ymekuria Mar 13, 2024
9e495eb
feat(BasicMerkleTreeContract.ts): make update @method async
ymekuria Mar 13, 2024
7198fe4
feat(LedgerContract.ts): make initState and sendBalance methods async
ymekuria Mar 13, 2024
400ffdd
feat(main.ts): add async/await to transaction callbacks and contract …
ymekuria Mar 13, 2024
c5a34f5
feat(OffChainStorageTestContract.ts): change update method to be async
ymekuria Mar 13, 2024
d3378d5
feat(messageBoardMain.ts): add async/await to transaction callbacks a…
ymekuria Mar 13, 2024
aa80ef0
refactor(NumberTreeContract): update contract
ymekuria Mar 13, 2024
22e4364
feat(NumberTreeContract.ts): make @methods async
ymekuria Mar 13, 2024
eea8180
feat(SignedMessageBoard.ts): make @methods async
ymekuria Mar 13, 2024
e5e1190
Merge remote-tracking branch 'origin/feature/async-circuits-code-comp…
ymekuria Mar 13, 2024
2d0fbfa
refactor(OracleExampleScaffold.ts): make the verify method async
ymekuria Mar 14, 2024
44be4bd
feat(OracleExampleScaffold.ts): make verify @method async
ymekuria Mar 14, 2024
c8e9f7b
feat(OracleExample.test.ts): add async/await to transaction callbacks…
ymekuria Mar 14, 2024
98ae022
feat(BasicTokenContract.ts): make init, mint, and sendTokens @methods…
ymekuria Mar 14, 2024
7dde45e
feat(main.ts): make transaction callbacks and contract calls async/await
ymekuria Mar 14, 2024
8d70b6c
feat(mainWhitelist.ts): add async/await to transaction callbacks and …
ymekuria Mar 14, 2024
0596341
feat(WhitelistedTokenContract.ts): make init, initState, mint, addToW…
ymekuria Mar 14, 2024
cfed698
feat(rollup.ts): make initStateRoot and update @methods async
ymekuria Mar 14, 2024
5eede17
feat(ProofsOnlyZkApp.ts): make init, add, incrementCalls, and callSec…
ymekuria Mar 14, 2024
8e33e9f
feat(SecondaryZkApp.ts): change init and add methods to be async
ymekuria Mar 14, 2024
97494e5
feat(main.ts): add async/await to transaction callbacks and contract …
ymekuria Mar 14, 2024
9e2ffa3
feat(MyToken.ts): make mintTokens, approveDeploy, approveTransfer, an…
ymekuria Mar 16, 2024
b7b2d9e
feat(ProofsOnlyZkApp.ts): change init and add, and incrementCalls @me…
ymekuria Mar 16, 2024
0d10b8e
feat(TokenPool.ts): make moveMinaToWrappedMina, moveWrappedMinaToMina…
ymekuria Mar 16, 2024
43ccf26
refactor(TokenUser.ts): make sendMyTokens transferAway @methods async
ymekuria Mar 16, 2024
7fbfc08
feat(WrappedMina.ts): make init, mintWrappedMina, redeemWrappedMinaAp…
ymekuria Mar 16, 2024
1d75ebc
feat(wrappedMinaMain.ts): add async/await to transaction callbacks an…
ymekuria Mar 16, 2024
1e501e3
feat(main.ts): add async/await to transaction callbacks and contract…
ymekuria Mar 16, 2024
af1f85d
feat(message.ts): make publishMessage @method async
ymekuria Mar 16, 2024
fbd1ef1
feat(Square.ts): make the update @method async
ymekuria Mar 16, 2024
b119537
feat(main.ts): add async/awaity to transaction callbacks and contract…
ymekuria Mar 16, 2024
91b1011
feat(faq.mdx): update code examples in FAQ to use async @methods
ymekuria Mar 17, 2024
f163df3
feat(getting-started-zkapps.mdx): update @methods in code snippets to…
ymekuria Mar 17, 2024
8888379
docs(zkapps): make the update @method in code example async
ymekuria Mar 17, 2024
ac1c081
docs(custom-tokens.mdx): make @methods in code examples async
ymekuria Mar 17, 2024
b2279d7
docs(events.mdx): make the updateMerkleTree @method code snippet async
ymekuria Mar 17, 2024
6492e76
docs(fetch-events-and-actions.mdx): make code snippet getActionsExamp…
ymekuria Mar 17, 2024
b1ed099
feat(foreign-fields.mdx): change myMethod to be async
ymekuria Mar 17, 2024
38a1086
feat(o1js): make @methods async in code snippets
ymekuria Mar 17, 2024
47647a2
feat(merkle-tree.mdx): make guessPreimage and claimReward methods asy…
ymekuria Mar 17, 2024
877280a
feat(on-chain-values.mdx): make the vote method async
ymekuria Mar 17, 2024
41f92f4
feat(permissions.mdx): make @methods async
ymekuria Mar 17, 2024
22aa458
feat(recursion.mdx): make the foo method async
ymekuria Mar 17, 2024
6cc39d8
feat(tutorials): change @methods to be async in tutorial code snippets
ymekuria Mar 17, 2024
0bf0226
feat(main.ts): add async/await to transaction callbacks and contract …
ymekuria Mar 17, 2024
e074e57
feat(main.ts): make the update function in async
ymekuria Mar 25, 2024
7aa8ccc
fix(main.ts): add aysnc/await to contract calls
ymekuria Mar 25, 2024
2fe6286
refactor(main.ts): change doUpdate function to be async
ymekuria Mar 25, 2024
4282e44
feat(zkappWorker.ts): add async/await to all tranaction callbacks and…
ymekuria Mar 25, 2024
65ddcb6
feat(how-to-write-a-zkapp-ui.mdx): update code snippet to use async c…
ymekuria Mar 25, 2024
a50b2a5
feat(testing-zkapps-locally.mdx): add async/await to contract calls i…
ymekuria Mar 25, 2024
f5c1606
feat(o1js): change transaction callbacks and contract call code snipp…
ymekuria Mar 25, 2024
1f297bd
feat(o1js): add async/await to transactions callbacks in permissions …
ymekuria Mar 25, 2024
592ec08
fix(permissions.mdx): add async/await to the transaction callbacks an…
ymekuria Mar 26, 2024
bd9e15a
feat(tutorials): change deploy and update contract calls to be async
ymekuria Mar 26, 2024
f4b7c35
feat(docs): update code snippets in tutorials to use async circuits
ymekuria Mar 26, 2024
a5d8e23
fix(docs): make contract calls async in code snippets
ymekuria Mar 26, 2024
ac72266
chore(package.json): update o1js peer dependency version to "0.1.*"
ymekuria Mar 27, 2024
ae1d099
chore(package.json): update o1js peer dependency version to 1.0.* in …
ymekuria Mar 27, 2024
344ec35
chore(package.json): update o1js dependency version to 1.0.* in multi…
ymekuria Mar 27, 2024
1302c16
merge main into feature/async-circuits-code-compatibility
ymekuria Apr 4, 2024
24ecffc
feat(zkapps): Add async in transcation callback
ymekuria Apr 4, 2024
6f96485
feat(custom-tokens.mdx): make the approveBase @method async
ymekuria Apr 4, 2024
fd9c90e
Merge branch 'main' into feature/async-circuits-code-compatibility
ymekuria Apr 4, 2024
9494db4
Merge branch 'main' into feature/async-circuits-code-compatibility
ymekuria Apr 9, 2024
06cd903
chore(o1-hello-world): update o1js to v 0.18.0
ymekuria Apr 9, 2024
06ce067
chore(02-private-inputs-and-hash-functions): update o1js to v 0.18.0
ymekuria Apr 9, 2024
7a66eec
chore(04-zkapp-browser-uis/ui): update o1js to v 0.18.*
ymekuria Apr 9, 2024
006e4b3
chore(04-zkapp-browser-uis/contracts): update o1js to v 0.18.*
ymekuria Apr 9, 2024
0313625
chore(05-common-types-and-functions): update o1js peer dependency to …
ymekuria Apr 9, 2024
8fbcb54
chore(experimental-zkapp-offchain-storage): update o1js peer dependen…
ymekuria Apr 9, 2024
3dae6ec
chore(offchain-storage-zkapp): update o1js peer dependency to v 0.18.*
ymekuria Apr 9, 2024
d70e01e
chore(offchain-storage-zkapp): update o1js peer dependency to v 0.18.*
ymekuria Apr 9, 2024
1eb5cf0
chore(07-oracles/contracts): update o1js peer dependency to v 0.18.*
ymekuria Apr 9, 2024
eb40d6f
chore(09-recursion): update o1js to v 0.18.0
ymekuria Apr 9, 2024
e84c0fc
chore(10-account-updates): update o1js peer dependency to v 0.18.*
ymekuria Apr 9, 2024
1fde61f
chore(11-advanced-account-updates): update o1js peer dependency to v …
ymekuria Apr 9, 2024
e7d3e8d
chore(anonymous-message-board): update o1js peer dependency to v 0.18.*
ymekuria Apr 9, 2024
321ff06
chore(interacting-with-zkApps-server-side): update o1js peer dependen…
ymekuria Apr 9, 2024
75225e0
address feedback
ymekuria Apr 11, 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
4 changes: 2 additions & 2 deletions docs/zkapps/faq.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Use the appropriate module to work with the live network or with historical arch

### Does o1js compile my JavaScript code to an arithmetic circuit?

No, o1js **does NOT compile into anything else**. In contrast to other zk ecosystems, o1js is just a JS library. It creates zk circuits from user code by _executing_ that code. If you have a smart contract with a `@method myMethod()`, for example, o1js simply calls `myMethod();` during proof generation.
No, o1js **does NOT compile into anything else**. In contrast to other zk ecosystems, o1js is just a JS library. It creates zk circuits from user code by _executing_ that code. If you have a smart contract with a `@method async myMethod()`, for example, o1js simply calls `myMethod();` during proof generation.

This works because o1js sets up some global state - a "circuit" - where it collects variables and constraints. The use of functions like `Field.mul` or `Bool.assertEquals` inside your smart contract methods add corresponding variables and constraints to the global circuit.

Expand All @@ -83,7 +83,7 @@ The previous for-loop example just stitches together a fixed number of o1js comm

```ts
// bad
@method myMethod(x: Field, n: Field) {
@method async myMethod(x: Field, n: Field) {
let n0 = Number(n.toString()); // nope
for (let y = 0; y < n0; y += 5) {
x.equals(y).assertFalse();
Expand Down
2 changes: 1 addition & 1 deletion docs/zkapps/getting-started-zkapps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Add the logic for your smart contract.

1. Start experimenting with iterative development to build and test one method at a time. Add functionality to the smart contract by implementing a `@method`.

See `@method update()` in the [Add.ts](https://github.com/o1-labs/zkapp-cli/blob/main/templates/project-ts/src/Add.ts#L20-L24) example file.
See `@method async update()` in the [Add.ts](https://github.com/o1-labs/zkapp-cli/blob/main/templates/project-ts/src/Add.ts#L20-L24) example file.

1. Build the smart contract:

Expand Down
4 changes: 2 additions & 2 deletions docs/zkapps/how-to-write-a-zkapp-ui.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ To interact with your zkApp, users of your zkApp must have the Auro Wallet insta
// This is the public key of the deployed zkapp you want to interact with.
const zkAppAddress = 'B62qq8sm7JdsED6VuDKNWKLAi1Tvz1jrnffuud5gXMq3mgtd';

const tx = await Mina.transaction(() => {
const tx = await Mina.transaction(async () => {
const YourSmartContractInstance = new YourSmartContract(zkAppAddress);
YourSmartContractInstance.foo();
await YourSmartContractInstance.foo();
});

await tx.prove();
Expand Down
4 changes: 2 additions & 2 deletions docs/zkapps/o1js/custom-tokens.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ The usual implementation is as easy as this:


```ts
@method approveBase(forest: AccountUpdateForest) {
@method async approveBase(forest: AccountUpdateForest) {
this.checkZeroBalanceChange(forest);
}
```

However, if you want to do a custom implementation for every child account update, you can utilize the `forEachUpdate()` method.

```ts
@method
@method async
approveBase(updates: AccountUpdateForest) {
let totalBalanceChange = Int64.zero;

Expand Down
2 changes: 1 addition & 1 deletion docs/zkapps/o1js/events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MyContract extends SmartContract {
"update-merkle-leaf": Field,
}

@method updateMerkleTree(leaf: Field, ...) {
@method async updateMerkleTree(leaf: Field, ...) {
this.emitEvent("update-merkle-leaf", leaf);
// ...
}
Expand Down
2 changes: 1 addition & 1 deletion docs/zkapps/o1js/fetch-events-and-actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Within your smart contract, you can use `getActions()` to retrieve actions emitt
```ts
class MyContract extends SmartContract {
...
@method getActionsExample() {
@method async getActionsExample() {
// Get all actions for this zkApp
let pendingActions = this.reducer.getActions({
fromActionHash: actionsHash,
Expand Down
2 changes: 1 addition & 1 deletion docs/zkapps/o1js/foreign-fields.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class AlmostField17 extends Field17.AlmostReduced {}
class MyContract extends SmartContract {
@state(AlmostField17.provable) x = State<AlmostField17>();

@method myMethod(y: AlmostField17) {
@method async myMethod(y: AlmostField17) {
let x = y.mul(2);
this.x.set(x.assertAlmostReduced());
}
Expand Down
24 changes: 12 additions & 12 deletions docs/zkapps/o1js/interact-with-mina.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ You create transactions in o1js by calling `Mina.transaction(...)`, which takes
const sender = PublicKey.fromBase58('B62..'); // the user address
const zkapp = new MyContract(address); // MyContract is a SmartContract

const tx = await Mina.transaction(sender, () => {
zkapp.myMethod(someArgument);
const tx = await Mina.transaction(sender, async () => {
await zkapp.myMethod(someArgument);
});
```

Expand Down Expand Up @@ -135,8 +135,8 @@ await MyContract.compile(); // this might take a while

// ...

const tx = await Mina.transaction(sender, () => {
zkapp.myMethod(someArgument);
const tx = await Mina.transaction(sender, async () => {
await zkapp.myMethod(someArgument);
});
await tx.prove(); // this might take a while
```
Expand Down Expand Up @@ -192,15 +192,15 @@ To send MINA, use `this.send()` from a smart contract method:

```ts
class MyContract extends SmartContract {
@method payout(amount: UInt64) {
@method async payout(amount: UInt64) {
// TODO: logic that determines whether the user is allowed to claim this amount

this.send({ to: this.sender, amount });
}
}
```

The `@method payout()` pays out a given amount of nanoMINA to the sender of the transaction, which you get with `this.sender`.
The `@method async payout()` pays out a given amount of nanoMINA to the sender of the transaction, which you get with `this.sender`.

In a real zkApp, you would add conditions to this method to determine who can call it with which amounts.

Expand All @@ -209,8 +209,8 @@ To call this method in a transaction and print the result:
```ts
const MINA = 1e9;

const tx = await Mina.transaction(sender, () => {
zkapp.payout(UInt64.from(5 * MINA));
const tx = await Mina.transaction(sender, async () => {
await zkapp.payout(UInt64.from(5 * MINA));
});
await tx.prove();
console.log(tx.toPretty());
Expand Down Expand Up @@ -295,7 +295,7 @@ Here's the smart contract code:

```ts
class MyContract extends SmartContract {
@method deposit(amount: UInt64) {
@method async deposit(amount: UInt64) {
let senderUpdate = AccountUpdate.create(this.sender);
senderUpdate.requireSignature();
senderUpdate.send({ to: this, amount });
Expand Down Expand Up @@ -376,8 +376,8 @@ For example:
```ts
const sender = senderPrivateKey.toPublicKey(); // public key from sender's private key

const tx = await Mina.transaction(sender, () => {
zkapp.deposit(UInt64.from(5 * MINA));
const tx = await Mina.transaction(sender, async () => {
await zkapp.deposit(UInt64.from(5 * MINA));
});
await tx.prove();

Expand Down Expand Up @@ -439,7 +439,7 @@ const Network = Mina.Network('https://example.com/graphql');
Mina.setActiveInstance(Network);

// create the transaction, add proofs and signatures
const tx = await Mina.transaction(sender, () => {
const tx = await Mina.transaction(sender, async () => {
// ...
});
await tx.prove();
Expand Down
4 changes: 2 additions & 2 deletions docs/zkapps/o1js/merkle-tree.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Leaderboard extends SmartContract {
);
}

@method guessPreimage(guess: Field, account: Account, path: MerkleWitness) {
@method async guessPreimage(guess: Field, account: Account, path: MerkleWitness) {
// we fetch z from the chain
const z = this.z.get();
this.z.requireEquals(z);
Expand All @@ -135,7 +135,7 @@ class Leaderboard extends SmartContract {
this.root.set(newRoot);
}

@method claimReward(account: Account, path: MerkleWitness) {
@method async claimReward(account: Account, path: MerkleWitness) {
// we fetch the on-chain commitment
const root = this.root.get();
this.root.requireEquals(root);
Expand Down
2 changes: 1 addition & 1 deletion docs/zkapps/o1js/on-chain-values.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const endDate = UInt64.from(Date.UTC(2022, 10, 1));
class VotingApp extends SmartContract {
// ...

@method vote(...) {
@method async vote(...) {
this.network.timestamp.requireBetween(startDate, endDate);
// ...
}
Expand Down
26 changes: 13 additions & 13 deletions docs/zkapps/o1js/permissions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class UnsecureContract extends SmartContract {
});
}

@method withdraw(amount: UInt64) {
@method async withdraw(amount: UInt64) {
this.send({ to: this.sender, amount });
}
}
Expand All @@ -160,9 +160,9 @@ But first, notice that the permissions specified in the `init()` method have set
Take a look at the following malicious transaction that abuses this permission:

```ts
tx = await Mina.transaction(account1Address, () => {
tx = await Mina.transaction(account1Address, async () => {
let withdrawal = AccountUpdate.create(zkappAddress);
withdrawal.send({ to: account1Address, amount: 1e9 });
await withdrawal.send({ to: account1Address, amount: 1e9 });
});
await tx.sign([account1Key]).send();
```
Expand All @@ -184,9 +184,9 @@ If you try to run the same transaction as before, the manual account update fail
You can slightly modify the withdraw transaction to include a valid signature by adding `.requireSignature()` on the withdrawal account update and providing the private key of the smart contract account to `tx.send([zkappKey])`:

```ts
tx = await Mina.transaction(account1Address, () => {
tx = await Mina.transaction(account1Address, async () => {
let withdrawal = AccountUpdate.create(zkappAddress);
withdrawal.send({ to: account1Address, amount: 1e9 });
await withdrawal.send({ to: account1Address, amount: 1e9 });
withdrawal.requireSignature();
});
await tx.sign([account1Key, zkappKey]).send();
Expand Down Expand Up @@ -227,9 +227,9 @@ The contract already has an `@method` that you can use: `withdraw()`.
To create a withdrawal transaction that contains a valid proof:

```ts
tx = await Mina.transaction(account1Address, () => {
tx = await Mina.transaction(account1Address, async () => {
let zkapp = new UnsecureContract(zkappAddress);
zkapp.withdraw(UInt64.from(1e9));
await zkapp.withdraw(UInt64.from(1e9));
});
await tx.prove();
await tx.sign([account1Key, zkappKey]).send();
Expand Down Expand Up @@ -269,7 +269,7 @@ class UpgradeabilityImpossible extends SmartContract {
});
}

@method updateVerificationKey(vk: VerificationKey) {
@method async updateVerificationKey(vk: VerificationKey) {
this.account.verificationKey.set(vk);
}
}
Expand All @@ -280,8 +280,8 @@ But since `setVerificationKey` permission is specified to be `impossible`, invok

```ts
console.log('try upgrading vk');
tx = await Mina.transaction(feePayer, () => {
zkapp.updateVerificationKey(newVerificationKey);
tx = await Mina.transaction(feePayer, async () => {
await zkapp.updateVerificationKey(newVerificationKey);
});
await tx.prove();
await tx.sign([feePayerKey, zkappKey]).send();
Expand All @@ -303,7 +303,7 @@ Modify the method `updateVerificationKey` to do some checks before you can updat
For now, just check that you can provide an `x` that is greater than or equal to 5. If this check succeeds, then update the verification key.

```ts
@method updateVerificationKey(vk: VerificationKey, x: Field) {
@method async updateVerificationKey(vk: VerificationKey, x: Field) {
let y = Field(5);
x.gte(y).assertTrue();

Expand All @@ -324,8 +324,8 @@ Now when you invoke the `updateVerificationKey` method, the transaction generate

```ts
console.log('try upgrading vk');
tx = await Mina.transaction(feePayer, () => {
zkapp.updateVerificationKey(newVerificationKey);
tx = await Mina.transaction(feePayer, async () => {
await zkapp.updateVerificationKey(newVerificationKey);
});
await tx.prove();
await tx.sign([feePayerKey, zkappKey]).send();
Expand Down
4 changes: 2 additions & 2 deletions docs/zkapps/o1js/recursion.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const proof = await SimpleProgram.run(Field(0));
To verify this proof from within any method of your `SmartContract` class:

```typescript
@method foo(proof: SimpleProgram.Proof) {
@method async foo(proof: SimpleProgram.Proof) {
proof.verify().assertTrue();
const output: Field = proof.value;
// ...the rest of our method.
Expand Down Expand Up @@ -154,7 +154,7 @@ const proof2 = await AddOne.step(Field(2), proof1);
Finally, verify the proof from within a SmartContract like the earlier example:

```typescript
@method foo(proof: Proof) {
@method async foo(proof: Proof) {
proof.verify().assertTrue();
/* ... the rest of our method
* For example using the total value as the fee for some other transaction. */
Expand Down
20 changes: 10 additions & 10 deletions docs/zkapps/o1js/smart-contracts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Interaction with a smart contract happens by calling one or more of its _methods

```ts
class HelloWorld extends SmartContract {
@method myMethod(x: Field) {
@method async myMethod(x: Field) {
x.mul(2).assertEquals(5);
}
}
Expand Down Expand Up @@ -124,7 +124,7 @@ A method can modify on-chain state by using `this.<state>.set()`:
class HelloWorld extends SmartContract {
@state(Field) x = State<Field>();

@method setX(x: Field) {
@method async setX(x: Field) {
this.x.set(x);
}
}
Expand All @@ -140,7 +140,7 @@ This example _reads_ state:
class HelloWorld extends SmartContract {
@state(Field) x = State<Field>();

@method increment() {
@method async increment() {
// read state
const x = this.x.get();
this.x.requireEquals(x);
Expand Down Expand Up @@ -204,7 +204,7 @@ To modify the `increment()` method to accept a parameter:
class HelloWorld extends SmartContract {
@state(Field) x = State<Field>();

@method increment(xPlus1: Field) {
@method async increment(xPlus1: Field) {
const x = this.x.get();
this.x.requireEquals(x);

Expand Down Expand Up @@ -250,7 +250,7 @@ class HelloWorld extends SmartContract {

// ...

@method incrementSecret(secret: Field) {
@method async incrementSecret(secret: Field) {
const x = this.x.get();
this.x.requireEquals(x);

Expand Down Expand Up @@ -299,14 +299,14 @@ A powerful feature of zkApps is that they are composable, just like Ethereum sma

```ts
class HelloWorld extends SmartContract {
@method myMethod(otherAddress: PublicKey) {
@method async myMethod(otherAddress: PublicKey) {
const calledContract = new OtherContract(otherAddress);
calledContract.otherMethod();
}
}

class OtherContract extends SmartContract {
@method otherMethod() {}
@method async otherMethod() {}
}
```

Expand All @@ -327,7 +327,7 @@ To ensure other methods can use a return value of your `@method`, you must annot
Here's an example of returning a `Bool` called `isSuccess`:

```ts
@method otherMethod(): Bool { // annotated return type
@method async otherMethod(): Bool { // annotated return type
// ...
return isSuccess;
}
Expand Down Expand Up @@ -363,11 +363,11 @@ For example, the following smart contract uses the `Point` struct defined earlie
export class Grid extends SmartContract {
@state(Point) p = State<Point>();

@method init() {
@method async init() {
this.p.set(new Point({ x: Field(1), y: Field(2) }));
}

@method move(newPoint: Point) {
@method async move(newPoint: Point) {
const point = this.p.get();
this.p.requireEquals(point);

Expand Down
Loading
Loading