Skip to content

Commit

Permalink
feat(docs): Nuke CLI from docs (#5936)
Browse files Browse the repository at this point in the history
* removes CLI from docs
* updates aztec-cli codegen -> aztec-compile codegen
* removes everything from quickstart except setting up sandbox (maybe controversial but I think it's good) 

blocked until aztec-builder is introduced
  • Loading branch information
catmcgee authored Apr 29, 2024
1 parent 94a2d61 commit 9af68d8
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: How to compile a contract

Once you have written a [contract](../main.md) in Aztec.nr, you will need to compile it into an [artifact](./artifacts.md) in order to use it.

In this guide we will cover how to do so, both using the CLI and programmatically.
In this guide we will cover how to do so, both using the `aztec-nargo` command and programmatically.

We'll also cover how to generate a helper [TypeScript interface](#typescript-interfaces) and an [Aztec.nr interface](#noir-interfaces) for easily interacting with your contract from your typescript app and from other Aztec.nr contracts, respectively.

Expand Down Expand Up @@ -36,7 +36,7 @@ members = [
You can use the code generator to autogenerate type-safe typescript classes for each of your contracts. These classes define type-safe methods for deploying and interacting with your contract based on their artifact.

```bash
aztec-cli codegen ./aztec-nargo/output/target/path -o src/artifacts
aztec-builder codegen ./aztec-nargo/output/target/path -o src/artifacts
```

Below is typescript code generated from the [Token](https://github.com/AztecProtocol/aztec-packages/blob/master/noir-projects/noir-contracts/contracts/token_contract/src/main.nr) contract:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,17 @@ title: How to deploy a contract

# Deploying contracts

Once you have [compiled](../compiling_contracts/how_to_compile_contract.md) your contracts you can proceed to deploying them using the aztec-cli or using aztec.js which is a Typescript client to interact with the sandbox.
Once you have [compiled](../compiling_contracts/how_to_compile_contract.md) your contracts you can proceed to deploying them using aztec.js which is a Typescript client to interact with the sandbox.

## Prerequisites

- `aztec-cli` and `aztec-nargo` installed (go to [Sandbox and CLI section](../../sandbox/main.md) for installation instructions)
- `aztec-nargo` installed (go to [Sandbox and CLI section](../../sandbox/main.md) for installation instructions)
- contract artifacts ready (go to [How to Compile Contract](../compiling_contracts/how_to_compile_contract.md) for instructions on how to compile contracts)
- Aztec Sandbox running (go to [Sandbox section](../../getting_started/quickstart.md) for instructions on how to install and run the sandbox)

## Deploy

Contracts can be deployed using the `aztec-cli` or using the `aztec.js` library.

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs groupId="deployment-methods">
<TabItem value="cli" label="Aztec CLI">

```bash
aztec-cli deploy /path/to/contract/artifact.json
```

</TabItem>
<TabItem value="js" label="Aztec.js">

Pre-requisite - Compile the contract and generate a type-safe typescript class for it.
Contracts can be deployed using the `aztec.js` library.

Compile the contract:

Expand All @@ -40,7 +25,7 @@ aztec-nargo compile
Generate the typescript class:

```bash
aztec-cli codegen ./aztec-nargo/output/target/path -o src/artifacts
aztec-builder ./aztec-nargo/output/target/path -o src/artifacts
```

This would create a typescript file like `Example.ts` in `./src/artifacts`. Read more on the [compiling page](../compiling_contracts/how_to_compile_contract.md).
Expand All @@ -58,30 +43,9 @@ const exampleContract = await ExampleContract.at(
myWallet
);
```

</TabItem>
</Tabs>

### Deploy Arguments

There are several optional arguments that can be passed:
<Tabs groupId="deployment-methods">
<TabItem value="cli" label="Aztec CLI">

`aztec-cli deploy` takes 1 mandatory argument which is the path to the contract artifact 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.js` (run `aztec-cli example-contracts` to see the full list of contracts available).

The command also takes the following optional arguments:

- `-args <constructorArgs...>` (default: `[]`): Arguments to pass to the contract constructor.
- `--rpc-url <string>` (default: `http://localhost:8080`): URL of the PXE to connect to.
- `--public-key <string>` (default: `undefined`): Optional encryption public key for this contract.
Set this only if this contract is expected to receive private notes (in such a case the public key is used during the note encryption).
- `--salt <string>` (default: random value): Hexadecimal string used when computing the contract address of the contract being deployed.
By default is set to a random value.
Set it, if you need a deterministic contract address (same functionality as Ethereum's `CREATE2` opcode).

</TabItem>
<TabItem value="js" label="Aztec.js">

The `deploy(...)` method is generated automatically with the typescript class representing your contract.
Its arguments are `PXE` client and contract constructor arguments.
Expand All @@ -98,25 +62,12 @@ const tx = ExampleContract.deploy(pxe).send({
});
```

</TabItem>
</Tabs>

### Deploying token contract

To give you a more complete example we will deploy a `Token` contract whose artifacts are included in the `@aztec/noir-contracts.js` package.

The contract has `admin` as a constructor argument.
We will deploy the contract with the `aztec-cli` and pass the `admin` address as an argument.

<Tabs groupId="deployment-methods">
<TabItem value="cli" label="Aztec CLI">

```bash
aztec-cli deploy TokenContractArtifact --args 0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529
```

</TabItem>
<TabItem value="js" label="Aztec.js">
We will deploy the contract and pass the `admin` address as an argument.

```ts
const admin = AztecAddress.from(
Expand All @@ -127,34 +78,18 @@ const contract = await TokenContract.deploy(wallet, admin).send().deployed();
logger(`Contract deployed at ${contract.address}`);
```

</TabItem>
</Tabs>

If everything went as expected you should see the following output (with a different address):

> Contract deployed at `0x151de6120ae6628129ee852c5fc7bcbc8531055f76d4347cdc86003bbea96906`
If we pass the salt as an argument:

<Tabs groupId="deployment-methods">
<TabItem value="cli" label="Aztec CLI">

```bash
aztec-cli deploy TokenContractArtifact --args 0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529 --salt 0x123
```

</TabItem>
<TabItem value="js" label="Aztec.js">

```ts
const contract = await TokenContract.deploy(wallet, admin)
.send({ contractAddressSalt: Fr.fromString("0x123") })
.deployed();
```

</TabItem>
</Tabs>

the resulting address will be deterministic.

> **NOTE**: You can try running the deployment with the same salt the second time in which case the transaction will fail because the address has been already deployed to.
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@ Let's start with the account contract itself in Aztec.nr. Create [a new Aztec.nr

#include_code contract noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr rust

:::info
You can use [the Aztec CLI](../../../sandbox/main.md) to generate a new keypair if you want to use a different one:

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

```bash
Private Key: 0xc06461a031058f116f087bc0161b11c039648eb47e03bad3eab089709bf9b8ae
Public Key: 0x0ede151adaef1cfcc1b3e152ea39f00c5cda3f3857cef00decb049d283672dc713c0e184340407e796411f74b7383252f1406272b58fccad6fee203f8a6db474
```

:::

The important part of this contract is the `entrypoint` function, which will be the first function executed in any transaction originated from this account. This function has two main responsibilities: authenticating the transaction and executing calls. It receives a `payload` with the list of function calls to execute, and requests a corresponding auth witness from an oracle to validate it. You will find this logic implemented in the `AccountActions` module, which use the `AppPayload` and `FeePayload` structs:

#include_code entrypoint noir-projects/aztec-nr/authwit/src/account.nr rust
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,7 @@ Unlike on Ethereum, there are 2 types of events supported by Aztec: [encrypted](

Encrypted events can only be emitted by private functions and are encrypted using a public key of a recipient.
For this reason it is necessary to register a recipient in the Private Execution Environment (PXE) before encrypting the events for them.
Recipients can be registered using the Aztec CLI or Aztec.js:

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs groupId="events">
<TabItem value="cli" label="Aztec CLI">

```bash
aztec-cli register-recipient --address 0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529 --public-key 0x26e193aef4f83c70651485b5526c6d01a36d763223ab24efd1f9ff91b394ac0c20ad99d0ef669dc0dde8d5f5996c63105de8e15c2c87d8260b9e6f02f72af622 --partial-address 0x200e9a6c2d2e8352012e51c6637659713d336405c29386c7c4ac56779ab54fa7
```

</TabItem>
<TabItem value="js" label="Aztec.js">
Recipients can be registered using Aztec.js:

```ts
const aztecAddress = AztecAddress.fromString(
Expand All @@ -52,9 +39,6 @@ const completeAddress = CompleteAddress.create(
await pxe.registerRecipient(completeAddress);
```

</TabItem>
</Tabs>

:::info
If a note recipient is one of the accounts inside the PXE, we don't need to register it as a recipient because we already have the public key available. You can register a recipient as shown [here](../../deploying_contracts/how_to_deploy_contract.md)

Expand Down Expand Up @@ -105,28 +89,9 @@ To emit unencrypted logs you don't need to import any library. You call the cont
### Querying the unencrypted event

Once emitted, unencrypted events are stored in AztecNode and can be queried by anyone:
<Tabs groupId="events">
<TabItem value="cli" label="Aztec CLI">

```bash
aztec-cli get-logs --fromBlock 5
```

</TabItem>
<TabItem value="js" label="Aztec.js">

#include_code get_logs /yarn-project/end-to-end/src/fixtures/utils.ts typescript

</TabItem>
</Tabs>

Get logs functionality provides a variety of filtering options.
To display them run:

```bash
aztec-cli get-logs --help
```

## Costs

All event data is pushed to Ethereum as calldata by the sequencer and for this reason the cost of emitting an event is non-trivial.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,4 @@ That's it! We have successfully deployed a token contract to an instance of the

## Next Steps

Learn more about writing Aztec.nr contracts on the [next page](./aztecnr-getting-started.md).
Write your first smart contract on the [next page](./aztecnr-getting-started.md).
74 changes: 7 additions & 67 deletions docs/docs/developers/getting_started/aztecnr-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ The last thing we need to implement is the function in order to retrieve a count

This function is `unconstrained` which allows us to fetch data from storage without a transaction. We retrieve a reference to the `owner`'s `counter` from the `counters` Map. The `get_balance` function then operates on the owner's counter. This yields a private counter that only the private key owner can decrypt.

## Test with the CLI
## Compile

Now we've written a simple Aztec.nr smart contract, it's time to ensure everything works by testing with the CLI.
Now we've written a simple Aztec.nr smart contract, we can compile it with `aztec-nargo`.

### Compile the smart contract

Expand All @@ -147,63 +147,10 @@ This will compile the smart contract and create a `target` folder with a `.json`
After compiling, you can generate a typescript class. In the same directory, run this:

```bash
aztec-cli codegen target -o src/artifacts
aztec-builder target -o src/artifacts
```

### Deploy

You can use the previously generated artifact to deploy the smart contract. Our constructor takes two arguments - `initial_counter` and `owner` so let's make sure to pass those in.

`initial_counter` can be any uint. In this guide we'll pick 100, but you can pick anything.

For the `owner` you can get the account addresses in your sandbox by running:

```bash
aztec-cli get-accounts
```

This will return something like this:

```bash
➜ counter aztec-cli get-accounts
Accounts found:

Address: 0x2fd4503a9b855a852272945df53d7173297c1469cceda31048b85118364b09a3
Public Key: 0x27c20118733174347b8082f578a7d8fb84b3ad38be293715eee8119ee5cd8a6d0d6b7d8124b37359663e75bcd2756f544a93b821a06f8e33fba68cc8029794d9
Partial Address: 0x11ee4cb5330545b3e82ace531526bc1995501a5596a85f90e5e60f4c1ad204dc

Address: 0x054ae9af363c6388cc6242c6eb0ed8a5860c15290744c81ecd5109434f9bb8b1
Public Key: 0x08145e8e8d46f51cda8d4c9cad81920236366abeafb8d387002bad879a3e87a81570b04ac829e4c007141d856d5a36d3b9c464e0f3c1c99cdbadaa6bb93f3257
Partial Address: 0x23ae266d9f8905bc4ef42e1435560ac78f3b5b55eb99b85398eb7011cd38fd8c

Address: 0x0d919c38d75484f8dd410cebaf0e17ccd196901d554d88f81b7e079375a4335d
Public Key: 0x13e6151ea8e7386a5e7c4c5221047bf73d0b1b7a2ad14d22b7f73e57c1fa00c614bc6da69da1b581b09ee6cdc195e5d58ae4dce01b63bbb744e58f03855a94dd
Partial Address: 0x2cf8f09aef15e219bf782049a3183a8adfd1fa254bf62bea050dc9a28fc979a7
```

Use one of these `address`es as the `owner`. You can either copy it or export.

To deploy the counter contract, [ensure the sandbox is running](../sandbox/references/sandbox-reference.md) and run this in the root of your Noir project:

```bash
aztec-cli deploy contracts/counter/target/counter-Counter.json --args 100 0x0a0ab6320e2981cc543fedb9ad0f524c0a750397ca3372508d14af5b3c3c7cf0 --private-key 0x2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281
```

You can also test the functions by applying what you learned in the [quickstart](./quickstart.md).

Congratulations, you have now written, compiled, and deployed your first Aztec.nr smart contract!

Deploying your contract via the CLI will not register the deployed contract with the [PXE](../../learn/concepts/pxe/main.md). To do so, use `aztec-cli add-contract`.

```bash
aztec-cli add-contract --contract-artifact contracts/counter/target/counter-Counter.json --contract-address <contract-address>
```

:::note

You can also deploy contracts using Aztec.js. See [the next page](./aztecjs-getting-started.md) for details.

:::
You can now use the artifact and/or the TS class in your Aztec.js! If you skipped the Aztec.js getting-started guide, you can follow it [here](aztecjs-getting-started.md). This will teach you about deploying and calling contracts in Aztec.js.

## Install Noir LSP (recommended)

Expand All @@ -222,16 +169,9 @@ Update the `Noir: Nargo Path` field to point to your desired `aztec-nargo` execu

## What's next?

Now you can explore.

**Interested in learning more about how Aztec works under the hood?**

Understand the high level architecture on the [Core Components page](../../learn/about_aztec/technical_overview.md). You can also explore Aztec's [hybrid state model](../../learn/concepts/hybrid_state/main.md) and [the lifecycle of a transaction](../../learn/concepts/transactions.md).

**Want to write more contracts?**
The next recommmended steps are follow the tutorials in order. They will teach you more about contracts, Aztec.js, and how Aztec works in general.

Follow the series of tutorials, starting with the private voting contract [here](../tutorials/writing_private_voting_contract.md).
To follow the series of tutorials, start with the private voting contract [here](../tutorials/writing_private_voting_contract.md).

**Ready to dive into Aztec and Ethereum cross-chain communication?**
Alternatively, you can read about the high level architecture on the [Core Components page](../../learn/about_aztec/technical_overview.md). You can also explore Aztec's [hybrid state model](../../learn/concepts/hybrid_state/main.md) and [the lifecycle of a transaction](../../learn/concepts/transactions.md).

Read the [Portals page](../../learn/concepts/communication/cross_chain_calls.md) and learn how to practically implement portals in the [token bridge tutorial](../tutorials/token_portal/main.md).
4 changes: 2 additions & 2 deletions docs/docs/developers/getting_started/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ title: Getting Started

If this is your first time using Aztec, and you want to get started by learning by doing, head to the [Quickstart section](quickstart.md). This section is the entry point to:

1. Set up the Aztec sandbox and deploy a sample first contract with the CLI
2. Deploy and interact with a contract using Aztec.js
1. Set up the Aztec sandbox and deploy a sample first contract with Aztec.js
2. Interact with a contract using Aztec.js
3. Write your first smart contract in Aztec.nr

## Learn
Expand Down
Loading

0 comments on commit 9af68d8

Please sign in to comment.