Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit fb38e25

Browse files
committed
Spanis session 4
1 parent 0d11a4d commit fb38e25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+16075
-0
lines changed

beginner-es/session_4/README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# session_3
2+
3+
This starter full stack project has been generated using AlgoKit. See below for default getting started instructions.
4+
5+
## Setup
6+
7+
### Initial setup
8+
9+
1. Clone this repository locally.
10+
2. Install pre-requisites:
11+
- Make sure to have [Docker](https://www.docker.com/) installed and running on your machine.
12+
- Install `AlgoKit` - [Link](https://github.com/algorandfoundation/algokit-cli#install): The minimum required version is `1.3.0`. Ensure you can execute `algokit --version` and get `1.3.0` or later.
13+
- Bootstrap your local environment; run `algokit bootstrap all` within this folder, which will install Poetry, run `npm install` and `poetry install` in the root directory to install NPM and Python packages respectively, set up a `.venv` folder with a Python virtual environment and also install all Python dependencies.
14+
- For TypeScript projects, it will also run `npm install` to install NPM packages.
15+
- For all projects, it will copy `.env.template` to `.env`.
16+
- Run `algokit localnet start` to start a local Algorand network in Docker. If you are using VS Code launch configurations provided by the template, this will be done automatically for you.
17+
3. Open the project and start debugging / developing on:
18+
- [Backend](backend/README.md) - Refer to the README for more information on how to work with smart contracts.
19+
- [Frontend](frontend/README.md) - Refer to the README for more information on how to work with the frontend application.
20+
21+
22+
### Subsequently
23+
24+
1. If you update to the latest source code and there are new dependencies, you will need to run `algokit bootstrap all` again.
25+
2. Follow step 3 above.
26+
27+
### Continuous Integration / Continuous Deployment (CI/CD)
28+
29+
This project uses [GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions) to define CI/CD workflows, which are located in the [`.github/workflows`](./.github/workflows) folder. You can configure these actions to suit your project's needs, including CI checks, audits, linting, type checking, testing, and deployments to TestNet.
30+
31+
For pushes to `main` branch, after the above checks pass, the following deployment actions are performed:
32+
- The smart contract(s) are deployed to TestNet using [AlgoNode](https://algonode.io).
33+
- The frontend application is deployed to a provider of your choice (Netlify, Vercel, etc.). See [frontend README](frontend/README.md) for more information.
34+
35+
> Please note deployment of smart contracts is done via `algokit deploy` command which can be invoked both via CI as seen on this project, or locally. For more information on how to use `algokit deploy` please see [AlgoKit documentation](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/deploy.md).
36+
37+
## Tools
38+
39+
This project makes use of Python and React to build Algorand smart contracts and to provide a base project configuration to develop frontends for your Algorand dApps and interactions with smart contracts. The following tools are in use:
40+
41+
- Algorand, AlgoKit, and AlgoKit Utils
42+
- Python dependencies including Poetry, Black, Ruff or Flake8, mypy, pytest, and pip-audit
43+
- React and related dependencies including AlgoKit Utils, Tailwind CSS, daisyUI, use-wallet, npm, jest, playwright, Prettier, ESLint, and Github Actions workflows for build validation
44+
45+
It has also been configured to have a productive dev experience out of the box in [VS Code](https://code.visualstudio.com/), see the [backend .vscode](./backend/.vscode) and [frontend .vscode](./frontend/.vscode) folders for more details.
46+
47+
## Integrating with smart contracts and application clients
48+
49+
Refer to the [backend](backend/README.md) folder for overview of working with smart contracts, [frontend](frontend/README.md) for overview of the React project and the [frontend/contracts](frontend/src/contracts/README.md) folder for README on adding new smart contracts from backend as application clients on your frontend. The templates provided in these folders will help you get started.
50+
When you compile and generate smart contract artifacts, your frontend component will automatically generate typescript application clients from smart contract artifacts and move them to `frontend/src/contracts` folder, see [`generate:app-clients` in package.json](frontend/package.json). Afterwards, you are free to import and use them in your frontend application.
51+
52+
The frontend starter also provides an example of interactions with your AuctionClient in [`AppCalls.tsx`](frontend/src/components/AppCalls.tsx) component by default.
53+
54+
## Next Steps
55+
56+
You can take this project and customize it to build your own decentralized applications on Algorand. Make sure to understand how to use AlgoKit and how to write smart contracts for Algorand before you start.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[algokit]
2+
min_version = "v1.4.0"
3+
4+
[deploy]
5+
command = "npm run deploy:ci"
6+
environment_secrets = [
7+
"DEPLOYER_MNEMONIC",
8+
]
9+
10+
[deploy.localnet]
11+
environment_secrets = []
12+
13+
[generate.smart_contract]
14+
description = "Adds new smart contract to existing project"
15+
path = ".algokit/generators/create_contract"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
_task:
2+
- "echo '==== Successfully initialized new smart contract 🚀 ===='"
3+
4+
contract_name:
5+
type: str
6+
help: Name of your new contract.
7+
placeholder: "my-new-contract"
8+
default: "my-new-contract"
9+
10+
_templates_suffix: ".j2"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import beaker
2+
import pyteal as pt
3+
{% if preset_name == 'starter' %}
4+
5+
app = beaker.Application("{{ contract_name }}")
6+
{% elif preset_name == 'production' -%}
7+
from algokit_utils import DELETABLE_TEMPLATE_NAME, UPDATABLE_TEMPLATE_NAME
8+
9+
app = beaker.Application("{{ contract_name }}")
10+
11+
12+
@app.update(authorize=beaker.Authorize.only_creator(), bare=True)
13+
def update() -> pt.Expr:
14+
return pt.Assert(
15+
pt.Tmpl.Int(UPDATABLE_TEMPLATE_NAME),
16+
comment="Check app is updatable",
17+
)
18+
19+
20+
@app.delete(authorize=beaker.Authorize.only_creator(), bare=True)
21+
def delete() -> pt.Expr:
22+
return pt.Assert(
23+
pt.Tmpl.Int(DELETABLE_TEMPLATE_NAME),
24+
comment="Check app is deletable",
25+
)
26+
{% endif %}
27+
28+
@app.external
29+
def hello(name: pt.abi.String, *, output: pt.abi.String) -> pt.Expr:
30+
return output.set(pt.Concat(pt.Bytes("Hello, "), name.get()))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import * as algokit from '@algorandfoundation/algokit-utils'
2+
import { {{ contract_name.split('_')|map('capitalize')|join }}Client } from '../artifacts/{{ contract_name }}/client'
3+
4+
// Below is a showcase of various deployment options you can use in TypeScript Client
5+
export async function deploy() {
6+
console.log('=== Deploying {{ contract_name.split('_')|map('capitalize')|join }} ===')
7+
8+
const algod = algokit.getAlgoClient()
9+
const indexer = algokit.getAlgoIndexerClient()
10+
const deployer = await algokit.getAccount(
11+
{ config: algokit.getAccountConfigFromEnvironment('DEPLOYER'), fundWith: algokit.algos(3) },
12+
algod,
13+
)
14+
await algokit.ensureFunded(
15+
{
16+
accountToFund: deployer,
17+
minSpendingBalance: algokit.algos(2),
18+
minFundingIncrement: algokit.algos(2),
19+
},
20+
algod,
21+
)
22+
const isMainNet = await algokit.isMainNet(algod)
23+
const appClient = new {{ contract_name.split('_')|map('capitalize')|join }}Client(
24+
{
25+
resolveBy: 'creatorAndName',
26+
findExistingUsing: indexer,
27+
sender: deployer,
28+
creatorAddress: deployer.addr,
29+
},
30+
algod,
31+
)
32+
33+
{%- if preset_name == 'starter' %}
34+
const app = await appClient.deploy({
35+
onSchemaBreak: 'append',
36+
onUpdate: 'append',
37+
})
38+
{% elif preset_name == 'production' %}
39+
const app = await appClient.deploy({
40+
allowDelete: !isMainNet,
41+
allowUpdate: !isMainNet,
42+
onSchemaBreak: isMainNet ? 'append' : 'replace',
43+
onUpdate: isMainNet ? 'append' : 'update',
44+
})
45+
{% endif %}
46+
47+
// If app was just created fund the app account
48+
if (['create', 'replace'].includes(app.operationPerformed)) {
49+
algokit.transferAlgos(
50+
{
51+
amount: algokit.algos(1),
52+
from: deployer,
53+
to: app.appAddress,
54+
},
55+
algod,
56+
)
57+
}
58+
59+
const method = 'hello'
60+
const response = await appClient.hello({ name: 'world' })
61+
console.log(`Called ${method} on ${app.name} (${app.appId}) with name = world, received: ${response.return}`)
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
2+
_commit: 1.8.0
3+
_src_path: gh:algorandfoundation/algokit-beaker-default-template
4+
algod_port: 4001
5+
algod_server: http://localhost
6+
algod_token: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
7+
author_email: [email protected]
8+
author_name: Evert
9+
contract_name: auction
10+
deployment_language: typescript
11+
ide_vscode: true
12+
indexer_port: 8980
13+
indexer_server: http://localhost
14+
indexer_token: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
15+
preset_name: starter
16+
project_name: backend
17+
python_linter: none
18+
use_dispenser: false
19+
use_github_actions: false
20+
use_pre_commit: false
21+
use_python_black: true
22+
use_python_mypy: false
23+
use_python_pip_audit: true
24+
use_python_pytest: true
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root=true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
insert_final_newline = true
8+
9+
[*.py]
10+
indent_size = 4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# this file should contain environment variables specific to algokit localnet
2+
ALGOD_TOKEN=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
3+
ALGOD_SERVER=http://localhost
4+
ALGOD_PORT=4001
5+
INDEXER_TOKEN=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
6+
INDEXER_SERVER=http://localhost
7+
INDEXER_PORT=8980
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# this file should contain environment variables common to all environments/networks
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# this file contains algorand network settings for interacting with testnet via algonode
2+
ALGOD_SERVER=https://testnet-api.algonode.cloud
3+
INDEXER_SERVER=https://testnet-idx.algonode.cloud
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

0 commit comments

Comments
 (0)