-
Notifications
You must be signed in to change notification settings - Fork 598
feat(docs): New getting started flow #2957
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
Merged
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
0d6c439
update defi to DeFi, fmt
critesjosh c1a3a87
copy edits
critesjosh 9cf72d7
edits
critesjosh d853c28
update roadmap section
critesjosh acb4c01
remove engineering roadmap links
critesjosh b6041c8
add intro section
critesjosh 90f9c9e
Merge branch 'master' into docs/jc/add-intros-edits
critesjosh 3a0f6c6
intermediate intro to contracts, state model, acconts, cross chain ca…
catmcgee fcdac25
intermediate concept circuits
catmcgee 6741263
Merge branch 'docs/jc/add-intros-edits' of https://github.com/AztecPr…
critesjosh 0bc566e
Merge branch 'master' into docs/jc/add-intros-edits
critesjosh cfc987f
remove bc deprecated
critesjosh 9ee37fa
transactions and context
catmcgee ee78dde
conflicts
catmcgee bdf83ff
Merge branch 'master' into docs/jc/add-intros-edits
critesjosh 0284b0f
remove deprecated assert_contains_and_remove
catmcgee b665fb6
small restructure
catmcgee 61d3477
counter aztecnr getting started
catmcgee d6ce919
Merge remote-tracking branch 'origin/master' into new-getting-started…
catmcgee 5ff640d
merge with master
catmcgee f6d7b16
merge master
catmcgee 9f8510f
Resolved merge conflicts
catmcgee 3c03445
accidental change
catmcgee 2d5a3e2
accidental change
catmcgee 4c6fe41
Merge branch 'master' into new-getting-started-flow
catmcgee b5cb9a4
minor edits to quickstart
critesjosh 3c5bfaf
small edit
critesjosh 85ce60b
include_code macro
catmcgee d479f90
Merge branch 'master' into new-getting-started-flow
catmcgee 961994f
Merge branch 'master' into new-getting-started-flow
catmcgee 81b9d2f
boxes reference
catmcgee 57c7c33
Update docs/docs/dev_docs/cli/updating.md
catmcgee 22ca5b0
.test.cpp
catmcgee 49b1fe8
.test.cpp
catmcgee 8f65418
josh feedback
catmcgee 8ecf3c6
compile counter properly
catmcgee 7125a75
docs broken link
catmcgee df9f809
Merge branch 'master' into new-getting-started-flow
catmcgee 7d5e93d
Merge branch 'master' into new-getting-started-flow
catmcgee d563041
Merge branch 'new-getting-started-flow' of https://github.com/AztecPr…
critesjosh b101f9e
fix broken links
critesjosh 4b5dd4f
fix build and breakup outputs
critesjosh bbbf3bd
Merge branch 'master' into new-getting-started-flow
catmcgee ed87274
revert some changes to get it building
critesjosh ff9535d
Merge branch 'master' into new-getting-started-flow
critesjosh 4e5f51a
update test
catmcgee 051a880
Merge branch 'master' into new-getting-started-flow
catmcgee 57813fe
Merge branch 'master' into new-getting-started-flow
catmcgee 8dedde2
compiler version update
catmcgee 99f3372
redirects
catmcgee 4e7ed50
Merge branch 'master' into new-getting-started-flow
catmcgee 0037d58
Merge branch 'master' into new-getting-started-flow
critesjosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| --- | ||
| title: Aztec.js | ||
| --- | ||
|
|
||
| If you are looking for the API reference, go [here](../../apis/aztec-js/index.md). | ||
|
|
||
| ## Introduction | ||
|
|
||
| Aztec.js is a library that provides APIs for managing accounts and interacting with contracts on the Aztec network. It communicates with the [Private eXecution Environment (PXE)](https://docs.aztec.network/apis/pxe/interfaces/PXE) through a `PXE` implementation, allowing developers to easily register new accounts, deploy contracts, view functions, and send transactions. | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Create a new account | ||
|
|
||
| ```typescript | ||
| import { getSchnorrAccount } from "@aztec/aztec.js"; | ||
| import { GrumpkinPrivateKey } from "@aztec/types"; | ||
|
|
||
| const encryptionPrivateKey = GrumpkinPrivateKey.random(); | ||
| const signingPrivateKey = GrumpkinPrivateKey.random(); | ||
| const wallet = getSchnorrAccount( | ||
| pxe, | ||
| encryptionPrivateKey, | ||
| signingPrivateKey | ||
| ).waitDeploy(); | ||
| console.log(`New account deployed at ${wallet.getAddress()}`); | ||
| ``` | ||
|
|
||
| ### Deploy a contract | ||
|
|
||
| ```typescript | ||
| import { Contract } from "@aztec/aztec.js"; | ||
|
|
||
| const contract = await Contract.deploy(wallet, MyContractArtifact, [ | ||
| ...constructorArgs, | ||
| ]) | ||
| .send() | ||
| .deployed(); | ||
| console.log(`Contract deployed at ${contract.address}`); | ||
| ``` | ||
|
|
||
| ### Send a transaction | ||
|
|
||
| ```typescript | ||
| import { Contract } from "@aztec/aztec.js"; | ||
|
|
||
| const contract = await Contract.at(contractAddress, MyContractArtifact, wallet); | ||
| const tx = await contract.methods | ||
| .transfer(amount, recipientAddress) | ||
| .send() | ||
| .wait(); | ||
| console.log( | ||
| `Transferred ${amount} to ${recipientAddress} on block ${tx.blockNumber}` | ||
| ); | ||
| ``` | ||
|
|
||
| ### Call a view function | ||
|
|
||
| ```typescript | ||
| import { Contract } from "@aztec/aztec.js"; | ||
|
|
||
| const contract = await Contract.at(contractAddress, MyContractArtifact, wallet); | ||
| const balance = await contract.methods.getBalance(wallet.getAddress()).view(); | ||
| console.log(`Account balance is ${balance}`); | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| --- | ||
| title: CLI Commands | ||
| --- | ||
|
|
||
| Here you will find a reference to the commands available in the Aztec CLI. | ||
|
|
||
| ## Installation | ||
|
|
||
| This command will install the Aztec CLI. | ||
|
|
||
| ```bash | ||
| npm install -g @aztec/cli | ||
| ``` | ||
|
|
||
| ## Creating Accounts | ||
|
|
||
| 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): | ||
|
|
||
| #include_code create-account yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
|
|
||
| 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). | ||
|
|
||
| Save the Address and Private key as environment 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. | ||
|
|
||
| #include_code create-account-from-private-key yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
catmcgee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| For all commands that require a user's private key, the CLI will look for the `PRIVATE_KEY` environment variable in absence of an optional argument. | ||
|
|
||
| Let's double check that the accounts have been registered with the sandbox using the `get-accounts` command: | ||
|
|
||
| #include_code get-accounts yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
|
|
||
| You will see a that a number of accounts exist that we did not create. The Sandbox initializes itself with 3 default accounts. 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 a token contract using the `deploy` command, and set an address of the admin via a constructor argument. You can find the contract we are deploying [here](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr) (or write it for yourself in [this tutorial!](../tutorials/writing_token_contract.md)) | ||
| Make sure to replace this address with one of the two you created earlier. | ||
|
|
||
| #include_code deploy yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
|
|
||
| Save the contract address as an environment variable. We will use it later. | ||
|
|
||
| ```bash | ||
| export CONTRACT_ADDRESS=<Your new contract address> | ||
| ``` | ||
|
|
||
| - `--args` - Arguments to the constructor of the contract. In this case we have set an address as admin. | ||
|
|
||
| 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: | ||
|
|
||
| #include_code check-deploy yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
|
|
||
| ## Sending a Transaction | ||
|
|
||
| We can now send a transaction to the network. We will mint funds in the public domain. | ||
| To form and submit the transaction we will use the `send` command of `aztec-cli`. | ||
| The `send` command expect the function name as the first unnamed argument and the following named arguments: | ||
|
|
||
| - `--args` - The list of arguments to the function call. | ||
| - `--contract-artifact` - The artifact of the contract to call. | ||
| - `--contract-address` - The deployed address of the contract to call. | ||
| - `--private-key` - The private key of the sender. | ||
|
|
||
| #include_code send yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
|
|
||
| We called the [`mint_public`](https://github.com/AztecProtocol/aztec-packages/blob/87fa621347e55f82e36c70515c1824161eee5282/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr#L157C10-L157C10) function and provided it with the 2 arguments it expects: the recipient's address and the amount to be minted. Make sure to replace all addresses in this command with yours. | ||
|
|
||
| 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: | ||
|
|
||
| #include_code get-tx-receipt yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
|
|
||
| ## Calling an Unconstrained (View) Function | ||
|
|
||
| Now that the `mint_public` tx has been settled we can call the `balance_of_public` unconstrained function: | ||
|
|
||
| #include_code call yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
|
|
||
| The `call` command calls a read-only method on a contract, one that will not generate a transaction to be sent to the network. The arguments here are: | ||
|
|
||
| - `--args` - The address for which we want to retrieve the balance. | ||
| - `--contract-artifact` - The artifact of the contract we are calling. | ||
| - `--contract-address` - The address of the deployed contract | ||
|
|
||
| As you can see from the result, this address has a public balance of 543, as expected. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,144 +1,39 @@ | ||
| --- | ||
| title: Aztec CLI | ||
| title: Sandbox and CLI | ||
| --- | ||
|
|
||
| ## Introduction | ||
| The Aztec Sandbox is an environment for local development on the Aztec Network. It's easy to get setup with just a single, simple command, and contains all the components needed to develop and test Aztec contracts and applications. The Aztec CLI will allow you to interact with the sandbox. | ||
|
|
||
| The Aztec CLI is a command-line tool allowing the user to interact directly with the Aztec Network. | ||
| ## Components of the Aztec network | ||
|
|
||
| It aims to provide all of the functionality required to deploy and invoke contracts and query system state such as contract data, transactions and emitted logs. | ||
|
|
||
| ## Requirements | ||
|
|
||
| You should have [node.js](https://nodejs.org/en/download) installed with version >= 18. | ||
|
|
||
| To install the Aztec CLI run: | ||
|
|
||
| ```bash | ||
| npm install -g @aztec/cli | ||
| ``` | ||
|
|
||
| Or if you use yarn: | ||
|
|
||
| ```bash | ||
| yarn global add @aztec/cli | ||
| ``` | ||
|
|
||
| Then verify that it is installed with: | ||
|
|
||
| ```bash | ||
| aztec-cli -h | ||
| ``` | ||
|
|
||
| Once installed it is invoked via: | ||
|
|
||
| `aztec-cli [options] [command]` | ||
|
|
||
| ## 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 `PXE_URL` environment variable. | ||
|
|
||
| To test communication with the Sandbox, let's run the command: | ||
|
|
||
| #include_code block-number yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
|
|
||
| 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: | ||
|
|
||
| #include_code example-contracts yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
|
|
||
| You can see all of our example contracts in the monorepo [here](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/noir-contracts/src/contracts). | ||
|
|
||
| In the following sections there will be commands that require contracts as options. You can either specify the full directory path to the contract artifact, or you can use the name of one of these examples as the option value. This will become clearer later on. | ||
|
|
||
| ## Creating Accounts | ||
|
|
||
| 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): | ||
|
|
||
| #include_code create-account yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
| Aztec's Layer 2 network is a fully programmable combined private/public ZK rollup. To achieve this, the network contains the following primary components: | ||
|
|
||
| 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). | ||
| - Aztec Node - Aggregates all of the 'backend' services necessary for the building and publishing of rollups. This packages is currently in development and much of the functionality is mocked. | ||
| - [Private Execution Environment (PXE)](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/pxe) - Normally residing with the end client, this decrypts and stores a client's private state, executes simulations and submits transactions to the Aztec Node. | ||
| - [Aztec.js](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/aztec.js) - Aztec's client library for interacting with the PXE (think Ethers.js). See the getting started guide [here](../getting_started/aztecjs-getting-started.md). | ||
|
|
||
| Save the Address and Private key as environment variables. We will be using them later. | ||
| All of this is included in the Sandbox, with the exception of Aztec.js which you can use to interact with it. | ||
|
|
||
| ```bash | ||
| export ADDRESS=<Address printed when you run the command> | ||
| export PRIVATE_KEY=<Private key printed when you run the command> | ||
| ``` | ||
| With the help of Aztec.js you will be able to: | ||
|
|
||
| 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. | ||
| - Create an account | ||
| - Deploy a contract | ||
| - Call view methods on contracts | ||
| - Simulate the calling of contract functions | ||
| - Send transactions to the network | ||
| - Be notified when transactions settle | ||
| - Query chain state such as chain id, block number etc. | ||
|
|
||
| #include_code create-account-from-private-key yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
| ## What's in the Sandbox? | ||
|
|
||
| For all commands that require a user's private key, the CLI will look for the `PRIVATE_KEY` environment variable in absence of an optional argument. | ||
| The sandbox contains a local Ethereum instance running [Anvil](https://book.getfoundry.sh/anvil/), a local instance of the Aztec rollup, an aztec private execution client for handling user transactions and state, and, if using Docker, an [Otterscan](https://github.com/otterscan/otterscan) block explorer for the local Ethereum network. | ||
|
|
||
| Let's double check that the accounts have been registered with the sandbox using the `get-accounts` command: | ||
| These provide a self contained environment which deploys Aztec on a local (empty) Ethereum network, creates 3 smart contract wallet accounts on the rollup, and allows transactions to be processed on the local Aztec sequencer. | ||
|
|
||
| #include_code get-accounts yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
| The current sandbox does not generate or verify proofs, but provides a working end to end developer flow for writing and interacting with Aztec.nr smart contracts. | ||
|
|
||
| You will see a that a number of accounts exist that we did not create. The Sandbox initializes itself with 3 default accounts. Save one of the printed accounts (not the one that you generated above) in an environment variable. We will use it later. | ||
| ## Aztec CLI | ||
|
|
||
| ```bash | ||
| export ADDRESS2=<Account address printed by the above command> | ||
| ``` | ||
| The Aztec CLI is a command-line tool allowing the user to interact directly with the Aztec network and sandbox. | ||
|
|
||
| ## Deploying a Token Contract | ||
|
|
||
| We will now deploy a token contract using the `deploy` command, and set an address of the admin via a constructor argument. | ||
| Make sure to replace this address with one of the two you created earlier. | ||
|
|
||
| #include_code deploy yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
|
|
||
| Save the contract address as an environment variable. We will use it later. | ||
|
|
||
| ```bash | ||
| export CONTRACT_ADDRESS=<Your new contract address> | ||
| ``` | ||
|
|
||
| - `--args` - Arguments to the constructor of the contract. In this case we have set an address as admin. | ||
|
|
||
| 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: | ||
|
|
||
| #include_code check-deploy yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
|
|
||
| ## Sending a Transaction | ||
|
|
||
| We can now send a transaction to the network. We will mint funds in the public domain. | ||
| To form and submit the transaction we will use the `send` command of `aztec-cli`. | ||
| The `send` command expect the function name as the first unnamed argument and the following named arguments: | ||
|
|
||
| - `--args` - The list of arguments to the function call. | ||
| - `--contract-artifact` - The artifact of the contract to call. | ||
| - `--contract-address` - The deployed address of the contract to call. | ||
| - `--private-key` - The private key of the sender. | ||
|
|
||
| #include_code send yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
|
|
||
| We called the `mint_public` function and provided it with the 2 arguments it expects: the recipient's address and the amount to be minted. Make sure to replace all addresses in this command with yours. | ||
|
|
||
| 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: | ||
|
|
||
| #include_code get-tx-receipt yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
|
|
||
| ## Calling an Unconstrained (View) Function | ||
|
|
||
| Now that the `mint_public` tx has been settled we can call the `balance_of_public` unconstrained function: | ||
|
|
||
| #include_code call yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash | ||
|
|
||
| The `call` command calls a read-only method on a contract, one that will not generate a transaction to be sent to the network. The arguments here are: | ||
|
|
||
| - `--args` - The address for which we want to retrieve the balance. | ||
| - `--contract-artifact` - The artifact of the contract we are calling. | ||
| - `--contract-address` - The address of the deployed contract | ||
|
|
||
| As you can see from the result, this address has a public balance of 543, as expected. | ||
|
|
||
| ## Compute Function Selector | ||
| `aztec-cli --compute-selector <signature e.g. foo(Field,Field)>` gives the function selector. | ||
|
|
||
| ## Inspect Contract | ||
| `aztec-cli --compute-selector <json artifact file e.g. artifacts/token_contract.json>` gives the list of all callable functions along with their function signature and selector. | ||
| It aims to provide all of the functionality required to deploy and invoke contracts and query system state such as contract data, transactions and emitted logs. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.