You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/docs/reference/developer_references/sandbox_reference/sandbox-reference.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -166,7 +166,7 @@ You can see all of our example contracts in the monorepo [here (GitHub link)](ht
166
166
If you wish to run components of the Aztec network stack separately, you can use the `aztec start` command with various options for enabling components.
Starting the aztec node alongside a PXE, sequencer or archiver, will attach the components to the node. Eg if you want to run a PXE separately to a node, you can [read this guide](../../../guides/developer_guides/local_env/run_more_than_one_pxe_sandbox.md).
With your project already set up, let's [connect to the Private eXecution Environment (PXE) running inside Sandbox and grab an account to interact with it](./1_pxe_service.md).
Copy file name to clipboardexpand all lines: docs/docs/tutorials/codealong/simple_dapp/1_pxe_service.md
+9-3
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ PXE is a component of the Aztec Protocol that provides a private execution envir
4
4
5
5
As an app developer, the PXE interface provides you with access to the user's accounts and their private state, as well as a connection to the network for accessing public global state.
6
6
7
-
During the Sandbox phase, this role is fulfilled by the [Aztec Sandbox](../../../reference/developer_references/sandbox_reference/index.md), which runs a local PXE and an Aztec Node, both connected to a local Ethereum development node like Anvil.
7
+
The [Aztec Sandbox](../../../reference/developer_references/sandbox_reference/index.md) runs a local PXE and an Aztec Node, both connected to a local Ethereum development node like Anvil.
8
8
The Sandbox also includes a set of pre-initialized accounts that you can use from your app.
9
9
10
10
In this section, we'll connect to the Sandbox from our project.
@@ -20,7 +20,13 @@ Let's create our first file `src/index.mjs` with the following contents:
20
20
21
21
#include_code all yarn-project/end-to-end/src/sample-dapp/connect.mjs javascript
22
22
23
-
Run this example as `node src/index.mjs` and you should see the following output:
23
+
Make sure the [Sandbox is running](../../../guides/developer_guides/getting_started.md) and run the example
Copy file name to clipboardexpand all lines: docs/docs/tutorials/codealong/simple_dapp/2_contract_deployment.md
+11-7
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,10 @@ Last, copy-paste the code from the `Token` contract into `contracts/token/main.n
30
30
31
31
### Helper files
32
32
33
+
:::info
34
+
Remove the `mod test;` line from `contracts/token/src/main.nr` as we will not be using TXE tests in this tutorial.
35
+
:::
36
+
33
37
The `Token` contract also requires some helper files. You can view the files [here (GitHub link)](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/noir-projects/noir-contracts/contracts/token_contract/src). Copy the `types.nr` and the `types` folder into `contracts/token/src`.
34
38
35
39
## Compile your contract
@@ -46,15 +50,15 @@ aztec-nargo compile
46
50
47
51
Let's now write a script for deploying your contracts to the Sandbox. We'll create a Private eXecution Environment (PXE) client, and then use the `ContractDeployer` class to deploy our contracts, and store the deployment address to a local JSON file.
48
52
49
-
Create a new file `src/deploy.mjs`:
53
+
Create a new file `src/deploy.mjs`. We import the contract artifacts we have generated plus the dependencies we'll need, and then we can deploy the contracts by adding the following code to the `src/deploy.mjs` file.
50
54
51
55
```js
52
56
// src/deploy.mjs
57
+
#include_code deploy-imports yarn-project/end-to-end/src/sample-dapp/deploy.mjs raw
#include_code dapp-deploy yarn-project/end-to-end/src/sample-dapp/deploy.mjs raw
60
64
@@ -64,12 +68,12 @@ main().catch((err) => {
64
68
});
65
69
```
66
70
67
-
We import the contract artifacts we have generated plus the dependencies we'll need, and then we can deploy the contracts by adding the following code to the `src/deploy.mjs` file. Here, we are using the `ContractDeployer` class with the compiled artifact to send a new deployment transaction. The `wait` method will block execution until the transaction is successfully mined, and return a receipt with the deployed contract address.
71
+
Here, we are using the `Contract` class with the compiled artifact to send a new deployment transaction. The `deployed` method will block execution until the transaction is successfully mined, and return a receipt with the deployed contract address.
68
72
69
-
Note that the token's `_initialize()` method expects an `owner` address to mint an initial set of tokens to. We are using the first account from the Sandbox for this.
73
+
Note that the token's `constructor()` method expects an `owner` address to set as the contract `admin`. We are using the first account from the Sandbox for this.
70
74
71
75
:::info
72
-
If you are using the generated typescript classes, you can drop the generic `ContractDeployer` in favor of using the `deploy` method of the generated class, which will automatically load the artifact for you and type-check the constructor arguments. SEe the [How to deploy a contract](../../../guides/developer_guides/smart_contracts/how_to_deploy_contract.md) page for more info.
76
+
If you are using the generated typescript classes, you can drop the generic `ContractDeployer` in favor of using the `deploy` method of the generated class, which will automatically load the artifact for you and type-check the constructor arguments. See the [How to deploy a contract](../../../guides/developer_guides/smart_contracts/how_to_deploy_contract.md) page for more info.
73
77
:::
74
78
75
79
Run the snippet above as `node src/deploy.mjs`, and you should see the following output, along with a new `addresses.json` file in your project root:
#include_code imports yarn-project/end-to-end/src/sample-dapp/contracts.mjs raw
24
22
```
25
23
26
-
And then add the following code for initializing the `Contract` instances:
24
+
You may have noticed that we are importing the `TokenContract` class from `@aztec/noir-contracts.js`. This is an alternative way to get the contract interface for interacting with the contract. With this, we can add the following code for initializing the `TokenContract` instance:
You can use the typescript autogenerated interface instead of the generic `Contract` class to get type-safe methods.
32
-
:::
28
+
We can now get the token instance in our main code in `src/index.mjs`, by importing the function from `src/contracts.mjs`. Update the imports in `src/index.mjs` to look like this:
29
+
30
+
```js
31
+
// src/index.mjs
32
+
#include_code imports yarn-project/end-to-end/src/sample-dapp/index.mjs raw
33
+
```
33
34
34
-
We can now get the token instance in our main code in `src/index.mjs`, and query the private balance for each of the user accounts. To query a function, without sending a transaction, use the `view` function of the method:
35
+
and query the private balance for each of the user accounts. To query a function, without sending a transaction, use the `simulate` function of the method:
Run this as`node src/index.mjs` and you should now see the following output:
39
+
Call the function in `main` and run this with`node src/index.mjs` and you should now see the following output:
39
40
40
41
```
41
-
Balance of 0x0c8a6673d7676cc80aaebe7fa7504cf51daa90ba906861bfad70a58a98bf5a7d: 100
42
+
Balance of 0x0c8a6673d7676cc80aaebe7fa7504cf51daa90ba906861bfad70a58a98bf5a7d: 0
42
43
Balance of 0x226f8087792beff8d5009eb94e65d2a4a505b70baf4a9f28d33c8d620b0ba972: 0
43
44
Balance of 0x0e1f60e8566e2c6d32378bdcadb7c63696e853281be798c107266b8c3a88ea9b: 0
44
45
```
45
46
46
-
## Transferring private tokens
47
+
## Mint tokens
47
48
48
-
Now that we can see the balance for each user, let's transfer tokens from one account to another. To do this, we will first need access to a `Wallet` object. This wraps access to an PXE and also provides an interface to craft and sign transactions on behalf of one of the user accounts.
49
+
Before we can transfer tokens, we need to mint some tokens to our user accounts. Add the following function to `src/index.mjs`:
49
50
50
-
We can initialize a wallet using one of the `getAccount` methods from the `accounts` package, along with the corresponding signing and encryption keys:
Call the function in `main`, run the script and after printing the balances of each account it will then privately mint tokens. After that completes, you should then see 20 tokens in the balance of the first account.
54
+
55
+
```text
56
+
Balance of 0x0c8a6673d7676cc80aaebe7fa7504cf51daa90ba906861bfad70a58a98bf5a7d: 20
57
+
Balance of 0x226f8087792beff8d5009eb94e65d2a4a505b70baf4a9f28d33c8d620b0ba972: 0
58
+
Balance of 0x0e1f60e8566e2c6d32378bdcadb7c63696e853281be798c107266b8c3a88ea9b: 0
59
59
```
60
60
61
-
For ease of use, `accounts` also ships with a helper `getInitialTestAccountsWallets` method that returns a wallet for each of the pre-initialized accounts in the Sandbox, so you can send transactions as any of them.
61
+
## Transferring private tokens
62
+
63
+
Now that we can see the balance for each user, let's transfer tokens from one account to another. To do this, we will first need access to a `Wallet` object. This wraps access to an PXE and also provides an interface to craft and sign transactions on behalf of one of the user accounts.
64
+
65
+
For ease of use, `@aztec/accounts` also ships with a helper `getInitialTestAccountsWallets` method that returns a wallet for each of the pre-initialized accounts in the Sandbox, so you can send transactions as any of them.
We'll use one of these wallets to initialize the `Contract` instance that represents our private token contract, so every transaction sent through it will be sent through that wallet.
71
+
We'll use one of these wallets to initialize the `TokenContract` instance that represents our private token contract, so every transaction sent through it will be sent through that wallet.
Let's set up our test suite. We'll make sure the Sandbox is running, create two fresh accounts to test with, and deploy an instance of our contract. `aztec.js` provides the helper functions we need to do this:
0 commit comments