Giter Site home page Giter Site logo

algoku's Introduction

algoku

This project has been generated using AlgoKit. See below for default getting started instructions.

Setup

Pre-requisites

Please note Puya smart contract development language is currently in alpha / developer preview. It is not recommended for production usage yet.

Initial setup

  1. Clone this repository locally
  2. Install pre-requisites:
    • Make sure to have Docker installed and running on your machine.
    • Install AlgoKit - Link: The recommended version is 1.7.3. Ensure you can execute algokit --version and get 1.7.1 or later.
    • Bootstrap your local environment; run algokit bootstrap all within this folder, which will:
      • Install Poetry - Link: The minimum required version is ^1.7. Ensure you can execute poetry -V and get 1.2+
      • Run poetry install in the root directory, which will set up a .venv folder with a Python virtual environment and also install all Python dependencies
      • Copy .env.template to .env
    • 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.
  3. Open the project and start debugging / developing via:
    • VS Code
      1. Open the repository root in VS Code
      2. Install recommended extensions
      3. Hit F5 (or whatever you have debug mapped to) and it should start running with breakpoint debugging.

        Note If using Windows: Before running for the first time you will need to select the Python Interpreter.

        1. Open the command palette (Ctrl/Cmd + Shift + P)
        2. Search for Python: Select Interpreter
        3. Select ./.venv/Scripts/python.exe
    • JetBrains IDEs (please note, this setup is primarily optimized for PyCharm Community Edition)
      1. Open the repository root in the IDE
      2. It should automatically detect it's a Poetry project and set up a Python interpreter and virtual environment.
      3. Hit Shift+F10|Ctrl+R (or whatever you have debug mapped to) and it should start running with breakpoint debugging. Please note, JetBrains IDEs on Windows have a known bug that in some cases may prevent executing shell scripts as pre-launch tasks, for workarounds refer to JetBrains forums.
    • Other
      1. Open the repository root in your text editor of choice
      2. In a terminal run poetry shell
      3. Run python -m smart_contracts through your debugger of choice

Subsequently

  1. If you update to the latest source code and there are new dependencies you will need to run algokit bootstrap all again
  2. Follow step 3 above

For guidance on smart_contracts folder and adding new contracts to the project please see README on the respective folder.### Continuous Integration / Continuous Deployment (CI/CD)

This project uses GitHub Actions to define CI/CD workflows, which are located in the .github/workflows folder.

Debugging Smart Contracts

This project is optimized to work with AlgoKit AVM Debugger extension. To activate it: Refer to the commented header in the __main__.py file in the smart_contracts folder.

If you have opted in to include VSCode launch configurations in your project, you can also use the Debug TEAL via AlgoKit AVM Debugger launch configuration to interactively select an available trace file and launch the debug session for your smart contract.

For information on using and setting up the AlgoKit AVM Debugger VSCode extension refer here. To install the extension from the VSCode Marketplace, use the following link: AlgoKit AVM Debugger extension.

Setting up GitHub for CI/CD workflow and TestNet deployment

  1. Every time you have a change to your smart contract, and when you first initialize the project you need to build the contract and then commit the smart_contracts/artifacts folder so the output stability tests pass
  2. Decide what values you want to use for the allow_update, allow_delete and the on_schema_break, on_update parameters specified in contract.py. When deploying to LocalNet these values are both set to allow update and replacement of the app for convenience. But for non-LocalNet networks the defaults are more conservative. These default values will allow the smart contract to be deployed initially, but will not allow the app to be updated or deleted if is changed and the build will instead fail. To help you decide it may be helpful to read the AlgoKit Utils app deployment documentation or the AlgoKit smart contract deployment architecture.
  3. Create a Github Environment named Test. Note: If you have a private repository and don't have GitHub Enterprise then Environments won't work and you'll need to convert the GitHub Action to use a different approach. Ignore this step if you picked Starter preset.
  4. Create or obtain a mnemonic for an Algorand account for use on TestNet to deploy apps, referred to as the DEPLOYER account.
  5. Store the mnemonic as a secret DEPLOYER_MNEMONIC in the Test environment created in step 3.
  6. The account used to deploy the smart contract will require enough funds to create the app, and also fund it. There are two approaches available here:
    • Either, ensure the account is funded outside of CI/CD. In Testnet, funds can be obtained by using the Algorand TestNet dispenser and we recommend provisioning 50 ALGOs.
    • Or, fund the account as part of the CI/CD process by using a DISPENSER_MNEMONIC GitHub Environment secret to point to a separate DISPENSER account that you maintain ALGOs in (similarly, you need to provision ALGOs into this account using the TestNet dispenser).

Continuous Integration

For pull requests and pushes to main branch against this repository the following checks are automatically performed by GitHub Actions:

  • Python dependencies are audited using pip-audit
  • Code formatting is checked using Black
  • Linting is checked using Ruff
  • Types are checked using mypy
  • Python tests are executed using pytest
  • Smart contract artifacts are built
  • Smart contract artifacts are checked for output stability
  • Smart contract is deployed to a AlgoKit LocalNet instance

Continuous Deployment

For pushes to main branch, after the above checks pass, the following deployment actions are performed:

  • The smart contract(s) are deployed to TestNet using AlgoNode.

Please note deployment is also performed 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.

Tools

This project makes use of Python to build Algorand smart contracts. The following tools are in use:

  • Algorand - Layer 1 Blockchain; Developer portal, Why Algorand?

  • AlgoKit - One-stop shop tool for developers building on the Algorand network; docs, intro tutorial

  • Puya - Smart contract development framework for developing Algorand smart contracts in pure Python; docs, examples

  • PyTEAL - Python language binding for Algorand smart contracts; docs

  • AlgoKit Utils - A set of core Algorand utilities that make it easier to build solutions on Algorand.

  • Poetry: Python packaging and dependency management.- Black: A Python code formatter.- Ruff: An extremely fast Python linter.

  • mypy: Static type checker.

  • pytest: Automated testing.

  • pip-audit: Tool for scanning Python environments for packages with known vulnerabilities.

  • pre-commit: A framework for managing and maintaining multi-language pre-commit hooks, to enable pre-commit you need to run pre-commit install in the root of the repository. This will install the pre-commit hooks and run them against modified files when committing. If any of the hooks fail, the commit will be aborted. To run the hooks on all files, use pre-commit run --all-files. It has also been configured to have a productive dev experience out of the box in VS Code, see the .vscode folder.

algoku's People

Contributors

code-alexander avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.