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: Boxes update #4498

Merged
merged 14 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 0 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -510,17 +510,6 @@ jobs:
name: "Test"
command: cond_spot_run_compose boxes 4 ./docker-compose.yml BOX=box-blank-react

boxes-token:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
steps:
- *checkout
- *setup_env
- run:
name: "Test"
command: cond_spot_run_compose boxes 4 ./docker-compose.yml BOX=box-token

end-to-end:
machine:
image: ubuntu-2204:2023.07.2
Expand Down Expand Up @@ -1262,10 +1251,6 @@ workflows:
requires:
- boxes
<<: *defaults
- boxes-token:
requires:
- boxes
<<: *defaults

# End to end tests.
- e2e-join:
Expand Down Expand Up @@ -1346,7 +1331,6 @@ workflows:
- pxe
- boxes-blank
- boxes-blank-react
- boxes-token
- cli-docs-sandbox
- guides-writing-an-account-contract
- guides-dapp-testing
Expand Down
2 changes: 1 addition & 1 deletion boxes/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

node_modules
dest
src/contracts/target
src/contracts/target

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions boxes/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
yarnPath: .yarn/releases/yarn-4.1.0.cjs
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-berry.cjs
logFilters:
- code: YN0013
level: discard
77 changes: 28 additions & 49 deletions boxes/blank-react/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,63 +1,42 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
parserOptions: {
project: './tsconfig.json',
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'prettier',
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"prettier",
],
settings: {
'import/resolver': {
"import/resolver": {
typescript: true,
node: true,
},
},
ignorePatterns: ['dest', 'webpack.config.js', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
overrides: [
{
files: ['*.ts', '*.tsx'],
parserOptions: {
project: true,
},
},
],
ignorePatterns: ["dest", "webpack.config.js", ".eslintrc.cjs"],
parser: "@typescript-eslint/parser",
plugins: ["react-refresh"],
rules: {
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-floating-promises': 2,
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
'require-await': 2,
'no-console': 'warn',
'no-constant-condition': 'off',
camelcase: 2,
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['client-dest'],
message: "Fix this absolute garbage import. It's your duty to solve it before it spreads.",
},
{
group: ['dest'],
message: 'You should not be importing from a build directory. Did you accidentally do a relative import?',
},
],
},
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
'import/no-unresolved': 'error',
'import/no-extraneous-dependencies': 'error',
"require-await": 2,
"no-console": "warn",
"no-constant-condition": "off",
camelcase: 2,
"import/no-unresolved": "error",
"import/no-extraneous-dependencies": "error",
},
};
7 changes: 4 additions & 3 deletions boxes/blank-react/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
!.yarn/releases

node_modules
dest
src/artifacts
src/contracts/target
dist
artifacts
src/contracts/target
src/contracts/log
79 changes: 15 additions & 64 deletions boxes/blank-react/README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,31 @@
This is a minimal [Aztec](https://aztec.network/) Noir smart contract and frontend bootstrapped with [`aztec-cli unbox`](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/cli). It is recommended you use the `aztec-cli unbox blank-react` command so that the repository is copied with needed modifications from the monorepo subpackage.
# Aztec Box

## Setup
This box is a one-stop-shop for Aztec that will deploy a blank React Page. You can use it as a boilerplate to start developing your own Aztec app in seconds!

Dependencies can be installed from the root of the package:
## Prerequisites

```bash
yarn
yarn install:noir
yarn install:sandbox
```

This sandbox requires [Docker](https://www.docker.com/) to be installed _and running_ locally. In the event the image needs updating, you can run `yarn install:sandbox` (see [sandbox docs](https://docs.aztec.network/developers/cli/main) for more information.)

In addition to the usual javascript dependencies, this project requires `nargo` (package manager) and `noir` (Aztec ZK smart contract language) in addition to `@aztec/aztec-cli`. The former two are installed by `yarn install:noir`.
- You should have Docker installed. If you don't, follow [this guide](https://docs.aztec.network/dev_docs/getting_started/quickstart#install-docker).

## Getting started
## Installation

After `yarn` has run,`yarn start:sandbox` in one terminal will launch a local instance of the Aztec sandbox via Docker Compose and `yarn start:dev` will launch a frontend app for deploying and interacting with an empty Aztec smart contract.
Run `npx create-aztec-app` and follow the instructions to clone this repo, install the sandbox and run it on port 8080.

At this point, [http://localhost:5173](http://localhost:5173) should provide a minimal smart contract frontend.

This folder should have the following directory structure:

```
|— README.md
|— package.json
|— src
|-config.ts - Blank Contract specific configuration for the frontend.
| You may need to update this if you modify the contract functions.
|— app
|— [frontend React .tsx code files]
|- scripts
|- [helpers for frontend to interact with contract on the sandbox]
|— contracts
|— src
| The Noir smart contract source files are here.
|— main.nr - the cloned noir contract, your starting point
|- interface.nr - autogenerated from main.nr when you compile
|— Nargo.toml [Noir build file, includes Aztec smart contract dependencies]
|— artifacts
| These are both generated from `contracts/` by the compile command
|— blank_contract.json
|— blank.ts
|— tests
| A simple end2end test deploying and testing the Blank contract deploys on a local sandbox
| The test requires the sandbox and anvil to be running (`yarn start:sandbox`).
| You can run the tests with `yarn test:integration`
|- blank.contract.test.ts
```
### 1. Install dependencies

Most relevant to you is likely `src/contracts/main.nr` (and the build config `src/contracts/Nargo.toml`). This contains the example blank contract logic that the frontend interacts with and is a good place to start writing Noir.

The `src/artifacts` folder can be re-generated from the command line
Run:

```bash
yarn compile
yarn
```

This will generate a [Contract ABI](src/artifacts/test_contract.json) and TypeScript class for the [Aztec smart contract](src/contracts/main.nr), which the frontend uses to generate the UI.
Time to build. Run:

Note: the `compile` command seems to generate a Typescript file which needs a single change -

```
import TestContractArtifactJson from 'text_contract.json' assert { type: 'json' };
// need to update the relative import to
import TestContractArtifactJson from './test_contract.json' assert { type: 'json' };
```bash
yarn dev
```

After compiling, you can re-deploy the updated noir smart contract from the web UI. The function interaction forms are generated from parsing the contract artifacts, so they should update automatically after you recompile.

## Learn More

To learn more about Noir Smart Contract development, take a look at the following resources:

- [Awesome Noir](https://github.com/noir-lang/awesome-noir) - learn about the Noir programming language.
Your React app is waiting for you on port 5176. Time to make it your own!

## Deploy on Aztec3
[Read the full Sandbox reference](https://docs.aztec.network/dev_docs/cli/sandbox-reference) for more info on what exactly is happening on your machine!

Coming Soon :)
Visit the [Aztec Docs](https://docs.aztec.network) for more information on how Aztec works, and the [Awesome Aztec Repository](https://github.com/AztecProtocol/awesome-aztec) for more cool projects, boilerplates and tooling.
25 changes: 25 additions & 0 deletions boxes/blank-react/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Private Token Noir Smart Contract</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/index.js"></script>
</body>
<style>
#root {
width: 100%;
text-align: center;
}

body {
display: flex;
place-items: center;
background: linear-gradient(#f6fbfc, #d8d4e7);
min-height: 100vh;
}
</style>
</html>
45 changes: 17 additions & 28 deletions boxes/blank-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
"private": true,
"version": "0.1.0",
"type": "module",
"main": "./dest/index.js",
"main": "./dist/index.js",
"scripts": {
"build": "yarn clean && yarn compile && yarn codegen && tsc -b && webpack",
"clean": "rm -rf ./dest .tsbuildinfo ./src/artifacts ./src/contracts/target",
"start": "serve -p 3000 ./dest",
"start:dev": "webpack serve --mode=development",
"compile": "cd src/contracts && ${AZTEC_NARGO:-aztec-nargo} compile",
"codegen": "${AZTEC_CLI:-aztec-cli} codegen src/contracts/target -o artifacts --ts",
"clean": "rm -rf ./dist .tsbuildinfo ./artifacts ./src/contracts/target",
"prep": "yarn clean && yarn compile && yarn codegen",
"dev": "yarn prep && webpack serve --mode development",
"build": "yarn prep && webpack",
"serve": "serve -p 3000 ./dist",
"formatting": "prettier --check ./src && eslint ./src",
"formatting:fix": "prettier -w ./src",
"compile": "cd src/contracts && ${AZTEC_NARGO:-aztec-nargo} compile",
"codegen": "${AZTEC_CLI:-aztec-cli} codegen src/contracts/target -o src/artifacts --ts",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --runInBand"
"test": "yarn prep && NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --runInBand"
},
"jest": {
"preset": "ts-jest/presets/default-esm",
Expand All @@ -28,13 +29,12 @@
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
"testRegex": "./src/.*\\.test\\.ts$",
"rootDir": "./src"
"testRegex": "tests/.*\\.test\\.ts$",
"rootDir": "./"
},
"dependencies": {
"@aztec/accounts": "^0.16.9",
"@aztec/aztec-ui": "^0.1.14",
"@aztec/aztec.js": "^0.16.9",
"@aztec/accounts": "latest",
"@aztec/aztec.js": "latest",
"classnames": "^2.3.2",
"formik": "^2.4.3",
"node-sass": "^9.0.0",
Expand All @@ -46,7 +46,6 @@
},
"devDependencies": {
"@types/jest": "^29.5.0",
"@types/mocha": "^10.0.3",
"@types/node": "^20.5.9",
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
Expand All @@ -62,10 +61,12 @@
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"html-webpack-plugin": "^5.6.0",
"jest": "^29.6.4",
"postcss": "^8.4.29",
"postcss-loader": "^7.3.3",
"prettier": "^3.1.1",
"react-toastify": "^10.0.4",
"resolve-typescript-plugin": "^2.0.1",
"stream-browserify": "^3.0.0",
"style-loader": "^3.3.3",
Expand All @@ -79,23 +80,11 @@
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
},
"browserslist": {
"production": [
">0.5%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"files": [
"dest",
"dist",
"src",
"!*.test.*"
],
"types": "./dest/index.d.ts",
"types": "./dist/index.d.ts",
"packageManager": "[email protected]"
}
9 changes: 0 additions & 9 deletions boxes/blank-react/src/@types/index.d.ts

This file was deleted.

Loading
Loading