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

feat(docs): adding some nitpick suggestions before sandbox release #1859

Merged
merged 6 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
7 changes: 4 additions & 3 deletions docs/docs/dev_docs/dapps/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Please use the [TUTORIAL-TEMPLATE](../../TUTORIAL_TEMPLATE.md) for standalone gu

Explain how to write a dapp using [`aztec.js`](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/aztec.js). Maybe that readme is enough?

- aztec.js
- aztec.js
- Docs outlining every typescript type.
- Q: can we use the tsdocs, or do we need something with a human touch (i.e. with careful explanations sandwiching the auto-generated interface data?)
- Docs outlining every external function:
Expand Down Expand Up @@ -32,11 +32,12 @@ Explain how to write a dapp using [`aztec.js`](https://github.com/AztecProtocol/
- How to filter for historic data in the historic block tree?
- How to query data from any of the trees (advanced)

FOR INSTRUCTIONS FOR BUILDING A WALLET, WE SHOULD WRITE DOCS [HERE](../wallets/building_a_wallet.md)
Copy link
Contributor

Choose a reason for hiding this comment

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

@iAmMichaelConnor I removed this link because it was giving me errors with running locally. That page does not exist.

FOR INSTRUCTIONS FOR BUILDING A WALLET, WE SHOULD WRITE DOCS HERE

ERRORS:

- Add any error explanations to [errors.md](../contracts/common_errors.md) (and break that file into multiple files if it's too unwieldy).

## Testing a dapp

Write about how to test a dapp using `aztec.js`. Maybe this overlaps with the e2e test stuff discussed above.
Write about how to test a dapp using `aztec.js`. Maybe this overlaps with the e2e test stuff discussed above.
87 changes: 59 additions & 28 deletions docs/docs/dev_docs/getting_started/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,50 @@ title: Aztec CLI

## Introduction

The Aztec CLI is a tool designed to enable a user to interact with the Aztec Network. Here we will provide a walk-through demonstrating how to use the CLI to deploy and test contracts on the [Aztec Sandbox](../sandbox/main.md).
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we will provide a walk-through demonstrating how to use the CLI to deploy and test contracts on the Aztec Sandbox

I think it's still beneficial to explain the goal of this page at the beginning.

Copy link
Contributor

Choose a reason for hiding this comment

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

agree. I will move it back up

The Aztec CLI is a tool designed to enable a user to interact with the Aztec Network.

## Requirements

The Aztec CLI is an npm package so you will need to have installed node.js >= 18. This tutorial will use the Aztec Sandbox so you should first set up the sandbox using the link above.
This tutorial will use the Aztec Sandbox so you should first set it up by following [the Aztec Sandbox instructions](../sandbox/main.md).

You should also have [node.js](https://nodejs.org/en/download) installed with version >= 18.

To install the Aztec CLI run:

`npm install -g @aztec/cli`
```bash
npm install -g @aztec/cli
```

Or if you use yarn:

`yarn global add @aztec/cli`
```bash
yarn global add @aztec/cli
```
Comment on lines +17 to +25
Copy link
Contributor

Choose a reason for hiding this comment

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

Not required for this PR, but we should eventually use tabs for expressing the same command across multiple languages / systems, because they're cool: https://docusaurus.io/docs/markdown-features/code-blocks#multi-language-support-code-blocks


Then verify that it is installed with:

`aztec-cli -h`
```bash
aztec-cli -h
```

## I have the Sandbox running, now what?

Lets first establish that we are able to communicate with the Sandbox. Most commands will require the url to the Sandbox, which defaults in the CLI to `http://localhost:8080`. You can override this as an option with each command or by setting `AZTEC_RPC_HOST` environment variable.

To test communication with the Sandbox, let's run the command:

`% aztec-cli block-number
1`
```bash
% aztec-cli block-number
1
```

You should see the current block number (1) printed to the screen!

## Contracts

We have shipped a number of example contracts in the `@aztec/noir-contracts` npm package. This is included with the cli by default so you are able to use these contracts to test with. To get a list of the names of the contracts run:

```
```bash
% aztec-cli example-contracts
ChildContractAbi
EasyPrivateTokenContractAbi
Expand All @@ -63,7 +73,7 @@ In the following sections there will be commands that require contracts as optio

The first thing we want to do is create a couple of accounts. We will use the `create-account` command which will generate a new private key for us, register the account on the sandbox, and deploy a simple account contract which [uses a single key for privacy and authentication](../../concepts/foundation/accounts/keys.md):

```
```bash
% aztec-cli create-account
Created new account:

Expand All @@ -75,9 +85,16 @@ Partial address: 0x72bf7c9537875b0af267b4a8c497927e251f5988af6e30527feb16299042e

Once the account is set up, the CLI returns the resulting address, its privacy key, and partial address. You can read more about these [here](../../concepts/foundation/accounts/keys.md#addresses-partial-addresses-and-public-keys).

Alternatively, we can also manually generate a private key and use it for creating the account, either via a `-k` option or by setting the `PRIVATE_KEY` environment variable.

Save the Address and Private key as environement variables. We will be using them later.

```bash
export ADDRESS=<Address printed when you run the command>
export PRIVATE_KEY=<Private key printed when you run the command>
```

Alternatively, we can also manually generate a private key and use it for creating the account, either via a `-k` option or by setting the `PRIVATE_KEY` environment variable.

```bash
% aztec-cli generate-private-key

Private Key: 0x6622c828e9cd5adc86f10878765fe921d2b8cb2c79bdbc391157e43811ce88e3
Expand All @@ -97,7 +114,7 @@ For all commands that require a user's private key, the CLI will look for the `P

Let's double check that the accounts have been registered with the sandbox using the `get-accounts` command:

```
```bash
% aztec-cli get-accounts
Accounts found:

Expand All @@ -110,30 +127,43 @@ Public key: 0x08aad54f32f1b6621ee5f25267166e160147cd355a2dfc129fa646a651dd2
Partial address: 0x72bf7c9537875b0af267b4a8c497927e251f5988af6e30527feb16299042ed
```

Save one of the printed accounts (not the one that you generated above) in an environment variable. We will use it later.

```bash
export ADDRESS2=<Account address printed by the above command>
```

## Deploying a Token Contract

We will now deploy the private token contract using the `deploy` command, minting 1000000 initial tokens to address `0x175310d40cd3412477db1c2a2188efd586b63d6830115fbb46c592a6303dbf6c`. Make sure to replace this address with one of the two you created earlier.

```
% aztec-cli deploy PrivateTokenContractAbi --args 1000000 0x175310d40cd3412477db1c2a2188efd586b63d6830115fbb46c592a6303dbf6c
```bash
% aztec-cli deploy PrivateTokenContractAbi --args 1000000 $ADDRESS

Contract deployed at 0x1ae8eea0dc265fb7f160dae62cc8912686d8a9ed78e821fbdd8bcedc54c06d0f
```

:::info
Save the contract address as an environment variable. We will use it later.

```bash
export CONTRACT_ADDRESS=<Your new contract address>
```

:::info
If you use a different address in the constructor above, you will get an error when running the deployment. This is because you need to register an account in the sandbox before it can receive private notes. When you create a new account, it gets automatically registered. Alternatively, you can register an account you do not own along with its public key using the `register-recipient` command.
:::

This command takes 1 mandatory positional argument which is the path to the contract ABI file in a JSON format (e.g. `contracts/target/PrivateToken.json`).
Alternatively you can pass the name of an example contract as exported by `@aztec/noir-contracts` (run `aztec-cli example-contracts` to see the full list of contracts available).

The command takes a few optional arguments while the most important one is:

- `--args` - Arguments to the constructor of the contract. In this case we have minted 1000000 initial tokens to the aztec address 0x175310d40cd3412477db1c2a2188efd586b63d6830115fbb46c592a6303dbf6c.

The CLI tells us that the contract was successfully deployed. We can use the `check-deploy` command to verify that a contract has been successfully deployed to that address:

```
% aztec-cli check-deploy --contract-address 0x1ae8eea0dc265fb7f160dae62cc8912686d8a9ed78e821fbdd8bcedc54c06d0f
```bash
% aztec-cli check-deploy --contract-address $CONTRACT_ADDRESS

Contract found at 0x1ae8eea0dc265fb7f160dae62cc8912686d8a9ed78e821fbdd8bcedc54c06d0f
```
Expand All @@ -142,11 +172,11 @@ Contract found at 0x1ae8eea0dc265fb7f160dae62cc8912686d8a9ed78e821fbdd8bcedc54c0

When we deployed the token contract, an initial supply of tokens was minted to the address provided in the constructor. We can now query the `getBalance()` method on the contract to retrieve the balance of that address. Make sure to replace the `contract-address` with the deployment address you got from the previous command, and the `args` with the account you used in the constructor.

```
```bash
% aztec-cli call getBalance \
--args 0x2337f1d5cfa6c03796db5539b0b2d5a57e9aed42665df2e0907f66820cb6eebe \
--args $ADDRESS \
--contract-abi PrivateTokenContractAbi \
--contract-address 0x1ae8eea0dc265fb7f160dae62cc8912686d8a9ed78e821fbdd8bcedc54c06d0f
--contract-address $CONTRACT_ADDRESS

View result: [
"{\"type\":\"bigint\",\"data\":\"1000000\"}"
Expand All @@ -165,12 +195,12 @@ As you can see from the result, this address has a balance of 1000000, as expect

We can now send a transaction to the network. We will transfer funds from the owner of the initial minted tokens to our other account. For this we will use the `send` command, which expects as arguments the quantity of tokens to be transferred, the sender's address, and the recipient's address. Make sure to replace all addresses in this command with the ones for your run.

```
```bash
% aztec-cli send transfer \
--args 543 0x2337f1d5cfa6c03796db5539b0b2d5a57e9aed42665df2e0907f66820cb6eebe 0x175310d40cd3412477db1c2a2188efd586b63d6830115fbb46c592a6303dbf6c \
--args 543 $ADDRESS $ADDRESS2 \
--contract-abi PrivateTokenContractAbi \
--contract-address 0x1ae8eea0dc265fb7f160dae62cc8912686d8a9ed78e821fbdd8bcedc54c06d0f \
--private-key 0x2aba9e7de7075deee3e3f4ad1e47749f985f0f72543ed91063cc97a40d851f1e
--contract-address $CONTRACT_ADDRESS \
--private-key $PRIVATE_KEY

Transaction has been mined
Transaction hash: 15c5a8e58d5f895c7e3017a706efbad693635e01f67345fa60a64a340d83c78c
Expand All @@ -184,10 +214,11 @@ We called the `transfer` function of the contract and provided these arguments:
- `--args` - The list of arguments to the function call.
- `--contract-abi` - The abi of the contract to call.
- `--contract-address` - The deployed address of the contract to call.
- `--private-key` - The private key of the sender

The command output tells us the details of the transaction such as its hash and status. We can use this hash to query the receipt of the transaction at a later time:

```
```bash
% aztec-cli get-tx-receipt 15c5a8e58d5f895c7e3017a706efbad693635e01f67345fa60a64a340d83c78c

Transaction receipt:
Expand All @@ -203,14 +234,14 @@ Transaction receipt:

Let's now call `getBalance()` on each of our accounts and we should see updated values:

```
% aztec-cli call getBalance -a 0x2337f1d5cfa6c03796db5539b0b2d5a57e9aed42665df2e0907f66820cb6eebe -c PrivateTokenContractAbi -ca 0x1ae8eea0dc265fb7f160dae62cc8912686d8a9ed78e821fbdd8bcedc54c06d0f
```bash
% aztec-cli call getBalance -a $ADDRESS -c PrivateTokenContractAbi -ca $CONTRACT_ADDRESS

View result: [
"{\"type\":\"bigint\",\"data\":\"999457\"}"
]

% aztec-cli call getBalance -a 0x175310d40cd3412477db1c2a2188efd586b63d6830115fbb46c592a6303dbf6c -c PrivateTokenContractAbi -ca 0x1ae8eea0dc265fb7f160dae62cc8912686d8a9ed78e821fbdd8bcedc54c06d0f
% aztec-cli call getBalance -a $ADDRESS2 -c PrivateTokenContractAbi -ca $CONTRACT_ADDRESS

View result: [
"{\"type\":\"bigint\",\"data\":\"543\"}"
Expand Down
2 changes: 1 addition & 1 deletion docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ const sidebars = {
id: "dev_docs/wallets/main",
},
items: [
"dev_docs/wallets/building_a_wallet",
"dev_docs/wallets/architecture",
Copy link
Contributor

Choose a reason for hiding this comment

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

"dev_docs/wallets/writing_an_account_contract",
],
},
Expand Down