├── Procfile
├── .gitignore
├── favicon.ico
├── screenshots
├── asset.png
├── balance.png
├── mainNet.png
├── login interface.png
├── transactionlist.png
├── Screenshot from 2022-09-27 14-55-34.png
├── Screenshot from 2022-09-27 21-50-09.png
├── Screenshot from 2022-09-27 21-50-44.png
└── Screenshot from 2022-09-27 22-39-11.png
├── front_end
├── public
│ ├── robots.txt
│ ├── favicon.ico
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── index.html
├── src
│ ├── setupTests.js
│ ├── App.test.js
│ ├── index.css
│ ├── reportWebVitals.js
│ ├── App.js
│ ├── App.css
│ ├── logo.svg
│ └── index.js
├── .gitignore
├── package.json
└── README.md
├── webapps
├── static
│ ├── img
│ │ └── favicon.ico
│ └── css
│ │ ├── nav.css
│ │ └── style.css
├── frontend_page
│ ├── success.html
│ ├── index.html
│ ├── mnemonic.html
│ ├── transactions.html
│ ├── layout.html
│ ├── login.html
│ ├── nft.html
│ ├── nav.html
│ ├── create_asset.html
│ ├── send.html
│ └── assets.html
├── __init__.py
├── index.py
├── admin_page.py
├── models.py
├── forms.py
├── views_pages.py
└── algodand.py
├── mypy.ini
├── wsgi.py
├── sandbox
├── requirements.txt
├── tests
└── test_account.py
├── .github
└── workflows
│ └── main.yaml
├── main.py
├── README.md
├── scripts
└── first_transaction_example.py
├── LICENSE
└── Notebooks
└── first_transaction.ipynb
/Procfile:
--------------------------------------------------------------------------------
1 | web: gunicorn wsgi:app
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /image
2 | .pyc
3 | /node_modules
--------------------------------------------------------------------------------
/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xerion12/Dapp-algorand/HEAD/favicon.ico
--------------------------------------------------------------------------------
/screenshots/asset.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xerion12/Dapp-algorand/HEAD/screenshots/asset.png
--------------------------------------------------------------------------------
/front_end/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/screenshots/balance.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xerion12/Dapp-algorand/HEAD/screenshots/balance.png
--------------------------------------------------------------------------------
/screenshots/mainNet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xerion12/Dapp-algorand/HEAD/screenshots/mainNet.png
--------------------------------------------------------------------------------
/front_end/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xerion12/Dapp-algorand/HEAD/front_end/public/favicon.ico
--------------------------------------------------------------------------------
/front_end/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xerion12/Dapp-algorand/HEAD/front_end/public/logo192.png
--------------------------------------------------------------------------------
/front_end/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xerion12/Dapp-algorand/HEAD/front_end/public/logo512.png
--------------------------------------------------------------------------------
/webapps/static/img/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xerion12/Dapp-algorand/HEAD/webapps/static/img/favicon.ico
--------------------------------------------------------------------------------
/screenshots/login interface.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xerion12/Dapp-algorand/HEAD/screenshots/login interface.png
--------------------------------------------------------------------------------
/screenshots/transactionlist.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xerion12/Dapp-algorand/HEAD/screenshots/transactionlist.png
--------------------------------------------------------------------------------
/mypy.ini:
--------------------------------------------------------------------------------
1 | [mypy]
2 |
3 | [mypy-pytest.*]
4 | ignore_missing_imports = True
5 |
6 | [mypy-algosdk.*]
7 | ignore_missing_imports = True
8 |
--------------------------------------------------------------------------------
/wsgi.py:
--------------------------------------------------------------------------------
1 | from webapps import create_app
2 |
3 | app = create_app()
4 | #main update
5 | if __name__ == "__main__":
6 | app.run(host='0.0.0.0')
7 |
--------------------------------------------------------------------------------
/screenshots/Screenshot from 2022-09-27 14-55-34.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xerion12/Dapp-algorand/HEAD/screenshots/Screenshot from 2022-09-27 14-55-34.png
--------------------------------------------------------------------------------
/screenshots/Screenshot from 2022-09-27 21-50-09.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xerion12/Dapp-algorand/HEAD/screenshots/Screenshot from 2022-09-27 21-50-09.png
--------------------------------------------------------------------------------
/screenshots/Screenshot from 2022-09-27 21-50-44.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xerion12/Dapp-algorand/HEAD/screenshots/Screenshot from 2022-09-27 21-50-44.png
--------------------------------------------------------------------------------
/screenshots/Screenshot from 2022-09-27 22-39-11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xerion12/Dapp-algorand/HEAD/screenshots/Screenshot from 2022-09-27 22-39-11.png
--------------------------------------------------------------------------------
/webapps/frontend_page/success.html:
--------------------------------------------------------------------------------
1 | {% extends 'layout.html' %}
2 |
3 | {% block content %}
4 | {% if success %}
5 |
Transaction Success
6 | {% else %}
7 | Transaction Failed
8 | {% endif %}
9 | {% endblock %}
10 |
--------------------------------------------------------------------------------
/webapps/frontend_page/index.html:
--------------------------------------------------------------------------------
1 | {% extends 'layout.html' %}
2 |
3 | {% block content %}
4 | Algorand Balance amount
5 | {{ balance }}
6 |
7 | {% endblock %}
8 |
--------------------------------------------------------------------------------
/webapps/frontend_page/mnemonic.html:
--------------------------------------------------------------------------------
1 | {% extends 'layout.html' %}
2 |
3 | {% block content %}
4 |
5 | Your Account Recovery Phrase:
6 |
7 | {{ passphrase }}
8 | Note this down and keep it secret!
9 | {% endblock %}
10 |
--------------------------------------------------------------------------------
/front_end/src/setupTests.js:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import '@testing-library/jest-dom';
6 |
--------------------------------------------------------------------------------
/front_end/src/App.test.js:
--------------------------------------------------------------------------------
1 | import { render, screen } from '@testing-library/react';
2 | import App from './App';
3 |
4 | test('renders learn react link', () => {
5 | render();
6 | const linkElement = screen.getByText(/learn react/i);
7 | expect(linkElement).toBeInTheDocument();
8 | });
9 |
--------------------------------------------------------------------------------
/sandbox:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | PARENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
5 | SANDBOX_DIR=$PARENT_DIR/_sandbox
6 | if [ ! -d "$SANDBOX_DIR" ]; then
7 | echo "Pulling sandbox..."
8 | git clone https://github.com/algorand/sandbox.git $SANDBOX_DIR
9 | fi
10 |
11 | $SANDBOX_DIR/sandbox "$@"
12 |
--------------------------------------------------------------------------------
/front_end/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 | # testing
8 | /coverage
9 | # production
10 | /build
11 | # misc
12 | .DS_Store
13 | .env.local
14 | .env.development.local
15 | .env.test.local
16 | .env.production.local
17 | npm-debug.log*
18 | yarn-debug.log*
19 | yarn-error.log*
20 |
--------------------------------------------------------------------------------
/webapps/__init__.py:
--------------------------------------------------------------------------------
1 | from flask import Flask
2 |
3 | from . import admin_page
4 | from . import views_pages
5 |
6 |
7 | def create_app():
8 | app = Flask(__name__)
9 | app.config["SECRET_KEY"] = "put any long random string here"
10 |
11 | admin_page.login_manager.init_app(app)
12 |
13 | app.register_blueprint(views_pages.main_bp)
14 | app.register_blueprint(admin_page.auth_bp)
15 |
16 | return app
17 |
--------------------------------------------------------------------------------
/front_end/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5 | sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | }
9 |
10 | code {
11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12 | monospace;
13 | }
14 |
--------------------------------------------------------------------------------
/front_end/src/reportWebVitals.js:
--------------------------------------------------------------------------------
1 | const reportWebVitals = onPerfEntry => {
2 | if (onPerfEntry && onPerfEntry instanceof Function) {
3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4 | getCLS(onPerfEntry);
5 | getFID(onPerfEntry);
6 | getFCP(onPerfEntry);
7 | getLCP(onPerfEntry);
8 | getTTFB(onPerfEntry);
9 | });
10 | }
11 | };
12 |
13 | export default reportWebVitals;
14 |
--------------------------------------------------------------------------------
/webapps/frontend_page/transactions.html:
--------------------------------------------------------------------------------
1 | {% extends 'layout.html' %}
2 |
3 | {% block content %}
4 | Transactions
5 |
11 |
12 |
13 | | Transfer |
14 | Quantity |
15 |
16 | {% for txn in txns %}
17 |
18 | | {{ txn.address }} |
19 | {{ txn.amount }} |
20 |
21 |
22 | {% endfor %}
23 |
24 | {% endblock %}
25 |
--------------------------------------------------------------------------------
/webapps/frontend_page/layout.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Wallet
9 |
10 |
11 | {% include 'nav.html' %}
12 |
13 |
14 | {% block content %} {% endblock %}
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/front_end/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | atomicwrites==1.4.0
2 | attrs==21.4.0
3 | cffi==1.15.0
4 | click==8.0.4
5 | colorama==0.4.5
6 | Flask==2.0.3
7 | Flask-Login==0.5.0
8 | flask-unittest==0.1.3
9 | Flask-WTF==1.0.1
10 | gunicorn==20.1.0
11 | iniconfig==1.1.1
12 | itsdangerous==2.0.1
13 | Jinja2==3.0.3
14 | MarkupSafe==2.0.1
15 | msgpack==1.0.4
16 | packaging==21.3
17 | pluggy==1.0.0
18 | py==1.11.0
19 | py-algorand-sdk
20 | pycparser==2.21
21 | pycryptodomex==3.14.1
22 | PyNaCl==1.5.0
23 | pyparsing==3.0.9
24 | pytest==7.0.1
25 | pyteal==0.9.1
26 | py-algorand-sdk==1.8.0
27 | mypy==0.910
28 | black==21.7b0
29 | python-dotenv==0.20.0
30 | tomli==1.2.3
31 | Werkzeug==2.0.3
32 | WTForms==3.0.0
--------------------------------------------------------------------------------
/front_end/src/App.js:
--------------------------------------------------------------------------------
1 | import logo from './logo.svg';
2 | import './App.css';
3 |
4 | function App() {
5 | return (
6 |
22 | );
23 | }
24 |
25 | export default App;
26 |
--------------------------------------------------------------------------------
/tests/test_account.py:
--------------------------------------------------------------------------------
1 | import unittest
2 |
3 | class TestTrans(unittest.TestCase):
4 |
5 |
6 | def setUp(self):
7 | self.sk, self.pk = account.generate_account()
8 | self.mnemonic_phrase = mnemonic.from_private_key(self.sk)
9 | self.user = User(passphrase=self.mnemonic_phrase)
10 | self.balance = get_balance(self.pk)
11 |
12 | def test_id(self):
13 | self.assertEqual(self.user.id, self.sk)
14 |
15 | def test_public_key(self):
16 | self.assertEqual(self.user.public_key, self.pk)
17 |
18 | def test_get_balance(self):
19 | self.assertEqual(self.balance, 0)
20 |
21 |
22 | if __name__ == '__main__':
23 | unittest.main()
--------------------------------------------------------------------------------
/webapps/frontend_page/login.html:
--------------------------------------------------------------------------------
1 | {% extends 'layout.html' %}
2 |
3 | {% block content %}
4 |
5 | Algorand Blockchain for Tenx Platform Certificate
6 | Login
7 |
16 | {% with messages = get_flashed_messages() %}
17 | {% if messages %}
18 | Passphrase not found
19 | {% else %}
20 |
21 | {% endif %}
22 | {% endwith %}
23 |
24 |
25 | {% endblock %}
--------------------------------------------------------------------------------
/webapps/frontend_page/nft.html:
--------------------------------------------------------------------------------
1 | {% extends 'layout.html' %}
2 |
3 | {% block content %}
4 | Certificate
5 | Post Certificate
6 |
12 |
13 |
14 | | Certificate ID |
15 | Tranee Name |
16 | Bid |
17 |
18 | {% for asset in assets %}
19 |
20 | | {{ asset.params.name }} |
21 | {{ asset.params.total }} |
22 | {{ asset.params.url }} |
23 |
24 | {% endfor %}
25 |
26 | {% endblock %}
27 |
--------------------------------------------------------------------------------
/front_end/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | text-align: center;
3 | }
4 |
5 | .App-logo {
6 | height: 40vmin;
7 | pointer-events: none;
8 | }
9 |
10 | @media (prefers-reduced-motion: no-preference) {
11 | .App-logo {
12 | animation: App-logo-spin infinite 20s linear;
13 | }
14 | }
15 |
16 | .App-header {
17 | background-color: #282c34;
18 | min-height: 100vh;
19 | display: flex;
20 | flex-direction: column;
21 | align-items: center;
22 | justify-content: center;
23 | font-size: calc(10px + 2vmin);
24 | color: white;
25 | }
26 |
27 | .App-link {
28 | color: #61dafb;
29 | }
30 |
31 | @keyframes App-logo-spin {
32 | from {
33 | transform: rotate(0deg);
34 | }
35 | to {
36 | transform: rotate(360deg);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/webapps/frontend_page/nav.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/webapps/frontend_page/create_asset.html:
--------------------------------------------------------------------------------
1 | {% extends 'layout.html' %}
2 |
3 | {% block content %}
4 | Create an Asset value
5 |
38 | {% endblock %}
--------------------------------------------------------------------------------
/webapps/frontend_page/send.html:
--------------------------------------------------------------------------------
1 | {% extends 'layout.html' %}
2 |
3 | {% block content %}
4 | Send Algorand
5 |
34 | Receive Algorand
35 | Your address is:
36 | {{ address }}
37 | {% endblock %}
--------------------------------------------------------------------------------
/webapps/frontend_page/assets.html:
--------------------------------------------------------------------------------
1 | {% extends 'layout.html' %}
2 |
3 | {% block content %}
4 | Assets
5 | Create an Asset
6 |
11 |
12 |
13 | | Asset Name |
14 | Unit Name |
15 | Total |
16 | Decimals |
17 | Frozen |
18 | URL |
19 |
20 | {% for asset in assets %}
21 |
22 | | {{ asset.params.name }} |
23 | {{ asset.params.get('unit-name') }} |
24 | {{ asset.params.total }} |
25 | {{ asset.params.decimals }} |
26 | {{ asset.params.get('default-frozen') }} |
27 | {{ asset.params.url }} |
28 |
29 | {% endfor %}
30 |
31 | {% endblock %}
32 |
--------------------------------------------------------------------------------
/front_end/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "front_end",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^5.16.5",
7 | "@testing-library/react": "^13.4.0",
8 | "@testing-library/user-event": "^13.5.0",
9 | "react": "^18.2.0",
10 | "react-dom": "^18.2.0",
11 | "react-scripts": "5.0.1",
12 | "web-vitals": "^2.1.4"
13 | },
14 | "scripts": {
15 | "start": "react-scripts start",
16 | "build": "react-scripts build",
17 | "test": "react-scripts test",
18 | "eject": "react-scripts eject"
19 | },
20 | "eslintConfig": {
21 | "extends": [
22 | "react-app",
23 | "react-app/jest"
24 | ]
25 | },
26 | "browserslist": {
27 | "production": [
28 | ">0.2%",
29 | "not dead",
30 | "not op_mini all"
31 | ],
32 | "development": [
33 | "last 1 chrome version",
34 | "last 1 firefox version",
35 | "last 1 safari version"
36 | ]
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/webapps/static/css/nav.css:
--------------------------------------------------------------------------------
1 | .topnav {
2 | background-color: rgb(82, 138, 202);
3 | text-align: center;
4 | width: 150px;
5 | position: absolute;
6 | height: 100%;
7 | padding-top: 50px;
8 | }
9 |
10 | /* Style the links inside the navigation bar */
11 | .topnav a {
12 | color: black;
13 | text-decoration: none;
14 | border-radius: 60px;
15 | font-size: 18px;
16 | display: block;
17 | padding: 15px;
18 | text-align: left;
19 | border: none;
20 | white-space: normal;
21 | float: none;
22 | outline: 0;
23 | }
24 |
25 | /* Change the color of links on hover */
26 | .topnav a:hover {
27 | background-color: lightgrey;
28 | color: black;
29 | }
30 |
31 | /* Add a color to the active/current link */
32 | .topnav a.active {
33 | background-color: darkslategrey;
34 | color: white;
35 | }
36 |
37 | .topnav a.logout {
38 | background-color: lightcoral;
39 | color: white;
40 | }
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/webapps/static/css/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: helvetica;
4 | color: rgb(72, 87, 86);
5 | }
6 |
7 | .container {
8 | display: flex;
9 | justify-content: center;
10 | padding-left: 30%;
11 | }
12 | .content {
13 | text-align: center;
14 | padding: 90px;
15 | margin: 0px;
16 | height: 70%;
17 | border-radius: 0px;
18 | background-color: rgb(58 131 249 / 50%);
19 | width: 93%;
20 | position: absolute;
21 | }
22 |
23 | input {
24 | width: 280px;
25 | padding: 15px;
26 | margin-bottom: 12px;
27 | border-radius: 6px;
28 | border: 2px solid grey;
29 | box-sizing: content-box;
30 | }
31 |
32 | input[type=submit] {
33 | font-size: 16px;
34 | font-weight: bold;
35 | border: 3px solid black;
36 | border-radius: 6px;
37 | width: 120px;
38 | background-color: white;
39 | color: black;
40 | }
41 |
42 | input[type=submit]:hover {
43 | background-color: darkslategrey;
44 | color: white;
45 | cursor: pointer;
46 | }
47 |
48 | table {
49 | text-align: left;
50 | margin-left: auto;
51 | margin-right: auto;
52 | }
53 |
54 | th, td {
55 | border-bottom: 1px solid rgb(14, 212, 247);
56 | padding: 4px;
57 | padding-right: 16px;
58 | }
59 |
--------------------------------------------------------------------------------
/.github/workflows/main.yaml:
--------------------------------------------------------------------------------
1 | # This is a basic workflow to help you get started with Actions
2 |
3 | name: CI
4 |
5 | # Controls when the workflow will run
6 | on:
7 | # Triggers the workflow on push or pull request events but only for the "main" branch
8 | push:
9 | branches: [ "main" ]
10 | pull_request:
11 | branches: [ "main" ]
12 |
13 | # Allows you to run this workflow manually from the Actions tab
14 | workflow_dispatch:
15 |
16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel
17 | jobs:
18 | # This workflow contains a single job called "build"
19 | build:
20 | # The type of runner that the job will run on
21 | runs-on: ubuntu-latest
22 |
23 | # Steps represent a sequence of tasks that will be executed as part of the job
24 | steps:
25 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
26 | - uses: actions/checkout@v3
27 |
28 | # Runs a single command using the runners shell
29 | - name: Run a one-line script
30 | run: echo Hello, world!
31 |
32 | # Runs a set of commands using the runners shell
33 | - name: Run a multi-line script
34 | run: |
35 | echo Add other actions to build,
36 | echo test, and deploy your project.
--------------------------------------------------------------------------------
/webapps/index.py:
--------------------------------------------------------------------------------
1 | from algosdk.constants import microalgos_to_algos_ratio
2 | from algosdk.v2client import indexer
3 |
4 | #home file update
5 | def myindexer():
6 | """Initialize and return an indexer"""
7 |
8 | algod_address = "https://testnet-algorand.api.purestake.io/idx2"
9 |
10 | algod_token = "XycLijM8J6aGrHCed8Tld3hNKfHFxWpF9eQ1d2gQ"
11 |
12 | headers = {
13 | "X-API-Key": algod_token,
14 | }
15 |
16 | return indexer.IndexerClient("", algod_address, headers)
17 |
18 | def get_transactions(address, substring):
19 | """Returns a list of transactions related to the given address"""
20 |
21 | response = myindexer().search_transactions(address=address, txn_type="pay")
22 | txns = []
23 | for txn in response["transactions"]:
24 | sender = txn["sender"]
25 | fee = txn["fee"]
26 |
27 | amount = txn["payment-transaction"]["amount"]
28 | if sender == address:
29 |
30 | # if the current account is the sender, add fee and display transaction as negative
31 | amount += fee
32 | amount *= -1
33 | other_address = txn["payment-transaction"]["receiver"]
34 | else:
35 | other_address = sender
36 |
37 | amount /= microalgos_to_algos_ratio
38 |
39 | # check for searched address
40 | if substring not in other_address:
41 | continue
42 |
43 | txns.append({"amount": amount, "address": other_address})
44 | return txns
45 |
46 |
47 | def get_assets(address, name):
48 | """Returns a list of assets that have been created by the given address"""
49 |
50 | response = myindexer().search_assets(creator=address, name=name)
51 | assets = response["assets"]
52 | return assets
53 |
--------------------------------------------------------------------------------
/webapps/admin_page.py:
--------------------------------------------------------------------------------
1 | from algosdk import mnemonic
2 | from flask import Blueprint, render_template, redirect, url_for, flash
3 | from flask_login import LoginManager, current_user, login_user
4 |
5 | from .algodand import create_account
6 | from .forms import LoginForm
7 | from .models import User
8 |
9 | login_manager = LoginManager()
10 |
11 | auth_bp = Blueprint(
12 | 'auth_bp', __name__,
13 | template_folder='frontend_page',
14 | static_folder='static'
15 | )
16 |
17 |
18 | @auth_bp.route('/login', methods=['GET', 'POST'])
19 | def login():
20 | """Default login page"""
21 | if current_user.is_authenticated:
22 | return redirect(url_for('main_bp.index'))
23 |
24 | form = LoginForm()
25 | if form.validate_on_submit():
26 | try:
27 | user = User(passphrase=form.passphrase.data)
28 | login_user(user)
29 | return redirect(url_for('main_bp.index'))
30 | except Exception as err:
31 | flash(err)
32 | return render_template('login.html', form=form)
33 | return render_template('login.html', form=form)
34 |
35 |
36 | @auth_bp.route('/signup', methods=['GET', 'POST'])
37 | def signup():
38 | """Generates a user account and shows its passphrase"""
39 | passphrase = create_account()
40 | user = User(passphrase=passphrase)
41 | login_user(user)
42 | return render_template('mnemonic.html', passphrase=passphrase)
43 |
44 |
45 | @login_manager.user_loader
46 | def load_user(user_id):
47 | """User load logic"""
48 | return User(mnemonic.from_private_key(user_id))
49 |
50 |
51 | @login_manager.unauthorized_handler
52 | def unauthorized():
53 | """Redirect unauthorized users to login page"""
54 | return redirect(url_for('auth_bp.login'))
55 |
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 |
2 | from algosdk.v2client import algod
3 | from algosdk import account, mnemonic
4 | from algosdk.future.transaction import AssetConfigTxn, wait_for_confirmation
5 |
6 | algod_address = "http://localhost:4001"
7 | algod_token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
8 | algod_client = algod.AlgodClient(algod_token, algod_address)
9 |
10 | # CREATE ASSET
11 | creator = account.generate_account()
12 |
13 | # Get network params for transactions before every transaction.
14 | params = algod_client.suggested_params()
15 |
16 | mnemonic_pharase = "emerge quarter always side worry table glow twelve divorce prize income whisper knife brave mention bench monitor march wait throw glue cover photo abandon arctic"
17 |
18 | creator = {
19 | "pk": "3QVNU6X57L35WGLR2WATU4XHRENJNWYSR54WVGQORYFSGM3JTTWISW6BLA",
20 | "sk": mnemonic.to_private_key(mnemonic_pharase) #sk = 'secret key'
21 | }
22 |
23 | # Asset Creation transaction
24 | txn = AssetConfigTxn(
25 | sender=creator['pk'],
26 | sp=params,
27 | total=10,
28 | default_frozen=False,
29 | unit_name="10Ac",
30 | asset_name="10 Academy",
31 | manager=creator['pk'],
32 | reserve=creator['pk'],
33 | freeze=creator['pk'], #put someone on the white or blacklist
34 | clawback=creator['pk'],
35 | url="https://10academy.org",
36 | decimals=0)
37 |
38 | # Sign with secret key of creator
39 | stxn = txn.sign(creator['sk'])
40 |
41 | # Send the transaction to the network and retrieve the txid.
42 | txid = algod_client.send_transaction(stxn)
43 | print("Signed transaction with txID: {}".format(txid))
44 |
45 | # Wait for the transaction to be confirmed
46 | confirmed_txn = wait_for_confirmation(algod_client, txid, 4)
47 | print("TXID: ", txid)
48 | print("Result confirmed in round: {}".format(confirmed_txn['confirmed-round']))
--------------------------------------------------------------------------------
/front_end/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | Algorand smart-contarct
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/webapps/models.py:
--------------------------------------------------------------------------------
1 | from algosdk import mnemonic
2 | from flask_login import UserMixin
3 |
4 | from .algodand import get_balance, send_txn, create_asset
5 | from .index import get_transactions, get_assets
6 |
7 | #model script update
8 | class User(UserMixin):
9 | """User account model"""
10 |
11 | def __init__(self, passphrase):
12 | """Creates a user using the 25-word mnemonic"""
13 | self.passphrase = passphrase
14 |
15 | @property
16 | def id(self):
17 | """Returns private key from mnemonic"""
18 | return mnemonic.to_private_key(self.passphrase)
19 |
20 | @property
21 | def public_key(self):
22 | """Returns public key from mnemonic. This is the same as the user's address"""
23 | return mnemonic.to_public_key(self.passphrase)
24 |
25 | def get_balance(self):
26 | """Returns user balance, in algos"""
27 | return get_balance(self.public_key)
28 |
29 | def send(self, quantity, receiver, note):
30 | """Returns True for a succesful transaction. Quantity is given in algos"""
31 | return send_txn(self.public_key, quantity, receiver, note, self.id)
32 |
33 | def create(
34 | self,
35 | asset_name,
36 | unit_name,
37 | total,
38 | decimals,
39 | default_frozen,
40 | url
41 | ):
42 | """Creates an asset, with the user as the creator"""
43 | return create_asset(
44 | self.public_key,
45 | asset_name,
46 | unit_name,
47 | total,
48 | decimals,
49 | default_frozen,
50 | url,
51 | self.id
52 | )
53 |
54 | def get_transactions(self, substring):
55 | """Returns a list of the user's transactions"""
56 | return get_transactions(self.public_key, substring)
57 |
58 | def get_assets(self, name):
59 | """Returns a list of the user's assets"""
60 | return get_assets(self.public_key, name)
61 |
--------------------------------------------------------------------------------
/webapps/forms.py:
--------------------------------------------------------------------------------
1 | from algosdk.constants import address_len, note_max_length, max_asset_decimals
2 | from flask_wtf import FlaskForm
3 | from wtforms import DecimalField, StringField, SubmitField, IntegerField, BooleanField
4 | from wtforms.validators import InputRequired, Optional, Length, NumberRange
5 | #file forms update
6 |
7 | class LoginForm(FlaskForm):
8 | """Form for logging into an account"""
9 | passphrase = StringField('25-word Passphrase', validators=[InputRequired()])
10 | submit = SubmitField('Login')
11 |
12 |
13 | class SendForm(FlaskForm):
14 | """Form for creating a transaction"""
15 | quantity = DecimalField(
16 | 'Quantity',
17 | validators=[InputRequired(), NumberRange(min=0)],
18 | render_kw={"placeholder": "Quantity to Send"}
19 | )
20 | receiver = StringField(
21 | 'Receiver',
22 | validators=[InputRequired(), Length(min=address_len, max=address_len)],
23 | render_kw={"placeholder": "Receiver Address"}
24 | )
25 | note = StringField(
26 | 'Note',
27 | validators=[Optional(), Length(max=note_max_length)],
28 | render_kw={"placeholder": "Note"})
29 | submit = SubmitField('Send')
30 |
31 |
32 | class AssetForm(FlaskForm):
33 | """Form for creating an asset"""
34 | asset_name = StringField(
35 | 'Asset name',
36 | validators=[InputRequired()]
37 | )
38 | unit_name = StringField(
39 | 'Unit name',
40 | validators=[InputRequired()]
41 | )
42 | total = IntegerField(
43 | 'Total number',
44 | validators=[InputRequired(), NumberRange(min=1)]
45 | )
46 | decimals = IntegerField(
47 | 'Number of decimals',
48 | validators=[InputRequired(), NumberRange(min=0, max=max_asset_decimals)]
49 | )
50 | default_frozen = BooleanField(
51 | 'Frozen',
52 | validators=[Optional()]
53 | )
54 | url = StringField(
55 | 'URL',
56 | validators=[Optional()]
57 | )
58 | submit = SubmitField('Create')
59 |
60 |
61 | class FilterForm(FlaskForm):
62 | """Form for filtering transactions and assets"""
63 | substring = StringField(
64 | 'Filter',
65 | validators=[Optional()],
66 | render_kw={"placeholder": "Filter list"}
67 | )
68 | submit = SubmitField('Search')
69 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # End-to-End Web3 dApp: Algorand NFTs and Smart Contracts
2 |
3 | ## Introduction
4 | Web3 is defined as a multi-layer architecture that leverages decentralized protocols and distributed technologies to provide a trusted application framework. At the core of this stack is a decentralized ledger system that enables consensus-based, tamper-proof data management. This architecture integrates several core components: programmable smart contracts that automate deterministic logic, NFTs for representing unique digital assets, decentralized storage mechanisms like IPFS for resilient data distribution, blockchain-based oracles for secure external data provisioning, and crypto wallets for user controlled identity and asset management. This composable technology stack is designed to support powerful, permissionless applications that operate independently of central authorities.
5 |
6 | ## Project Objective
7 | The project addresses the limitations of distributing certificates as static PDF files. The aim is to deliver certificates as digital assets (NFTs) on the Algorand blockchain, supporting on-chain verification, security, and additional functionality through smart contracts.
8 |
9 | ## Development Environment
10 |
11 | ### Algorand Sandbox (Testnet)
12 | Algorand offers a Docker-based sandbox for node setup and rapid development.
13 |
14 | ```bash
15 | git clone https://github.com/algorand/sandbox.git
16 | cd sandbox
17 | ./sandbox up testnet
18 | ./sandbox up testnet -v
19 | ```
20 |
21 | ### Python SDK Installation
22 | The Algorand Python SDK is available via pip.
23 |
24 | ```bash
25 | pip3 install py-algorand-sdk
26 | ```
27 | Instructions for account creation are provided at the official Algorand developer documentation.
28 |
29 | ### React Application Setup
30 | The sample implementation utilizes a React frontend available from an open-source repository:
31 |
32 | ```bash
33 | git clone https://github.com/BirhanuGebisa/Algorand-dapps_smart-contract.git
34 | cd algorand-NFTs-smartContracts
35 | npm start
36 | ```
37 | Access the local deployment at `http://localhost:8080`.
38 |
39 | ### Application Scripts
40 | - `npm test` initiates the interactive test runner.
41 | - `npm run build` optimizes the React application for production output.
42 |
43 | ### Backend Deployment
44 | Use Flask to run the backend logic:
45 |
46 | ```bash
47 | flask run
48 | ```
49 |
50 | A deployment instance is available at:
51 | https://lgorand-dapps-smart-contract.herokuapp.com/login
52 |
53 | ## Author
54 | dev.xerion@gmail.com
55 |
--------------------------------------------------------------------------------
/front_end/src/logo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/scripts/first_transaction_example.py:
--------------------------------------------------------------------------------
1 | import json
2 | import base64
3 | from algosdk import account, mnemonic, constants
4 | from algosdk.v2client import algod
5 | from algosdk.future import transaction
6 | #transaction update
7 | def generate_algorand_keypair():
8 | private_key, address = account.generate_account()
9 | print("My address: {}".format(address))
10 | print("My private key: {}".format(private_key))
11 | print("My passphrase: {}".format(mnemonic.from_private_key(private_key)))
12 |
13 | # Write down the address, private key, and the passphrase for later usage
14 | generate_algorand_keypair()
15 |
16 | def first_transaction_example(private_key, my_address):
17 | algod_address = "http://localhost:4001"
18 | algod_token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
19 | algod_client = algod.AlgodClient(algod_token, algod_address)
20 |
21 | print("My address: {}".format(my_address))
22 | account_info = algod_client.account_info(my_address)
23 | print("Account balance: {} microAlgos".format(account_info.get('amount')))
24 |
25 | # build transaction
26 | params = algod_client.suggested_params()
27 | # comment out the next two (2) lines to use suggested fees
28 | params.flat_fee = constants.MIN_TXN_FEE
29 | params.fee = 1000
30 | receiver = "3QVNU6X57L35WGLR2WATU4XHRENJNWYSR54WVGQORYFSGM3JTTWISW6BLA"
31 | amount = 100000
32 | note = "Hello World".encode()
33 |
34 | unsigned_txn = transaction.PaymentTxn(my_address, params, receiver, amount, None, note)
35 |
36 | # sign transaction
37 | signed_txn = unsigned_txn.sign(private_key)
38 |
39 | # submit transaction
40 | txid = algod_client.send_transaction(signed_txn)
41 | print("Signed transaction with txID: {}".format(txid))
42 |
43 | # wait for confirmation
44 | try:
45 | confirmed_txn = transaction.wait_for_confirmation(algod_client, txid, 4)
46 | except Exception as err:
47 | print(err)
48 | return
49 |
50 | print("Transaction information: {}".format(
51 | json.dumps(confirmed_txn, indent=4)))
52 | print("Decoded note: {}".format(base64.b64decode(
53 | confirmed_txn["txn"]["txn"]["note"]).decode()))
54 |
55 | print("Starting Account balance: {} microAlgos".format(account_info.get('amount')) )
56 | print("Amount transfered: {} microAlgos".format(amount) )
57 | print("Fee: {} microAlgos".format(params.fee) )
58 |
59 |
60 | account_info = algod_client.account_info(my_address)
61 | print("Final Account balance: {} microAlgos".format(account_info.get('amount')) + "\n")
62 |
63 |
64 |
65 | # replace private_key and my_address with your private key and your address.
66 | first_transaction_example("private key, address key")
--------------------------------------------------------------------------------
/front_end/src/index.js:
--------------------------------------------------------------------------------
1 | async function firstTransaction() {
2 |
3 | try {
4 | let myAccount = createAccount();
5 | console.log("Press any key when the account is funded");
6 | await keypress();
7 | // Connect your client
8 | const algodToken = '2f3203f21e738a1de6110eba6984f9d03e5a95d7a577b34616854064cf2c0e7b';
9 | const algodServer = 'https://academy-algod.dev.aws.algodev.network/';
10 | const algodPort = '';
11 | let algodClient = new algosdk.Algodv2(algodToken, algodServer, algodPort);
12 |
13 | //Check your balance
14 | let accountInfo = await algodClient.accountInformation(myAccount.addr).do();
15 | console.log("Account balance: %d microAlgos", accountInfo.amount);
16 | let startingAmount = accountInfo.amount;
17 | // Construct the transaction
18 | let params = await algodClient.getTransactionParams().do();
19 | // comment out the next two lines to use suggested fee
20 | // params.fee = 1000;
21 | // params.flatFee = true;
22 |
23 | // receiver defined as TestNet faucet address
24 | const receiver = "HZ57J3K46JIJXILONBBZOHX6BKPXEM2VVXNRFSUED6DKFD5ZD24PMJ3MVA";
25 | const enc = new TextEncoder();
26 | const note = enc.encode("Hello World");
27 | let amount = 100000;
28 | let closeout = receiver; //closeRemainderTo
29 | let sender = myAccount.addr;
30 | let txn = algosdk.makePaymentTxnWithSuggestedParams(sender, receiver, amount, closeout, note, params);
31 | // WARNING! all remaining funds in the sender account above will be sent to the closeRemainderTo Account
32 | // In order to keep all remaning funds in the sender account after tx, set closeout parameter to undefined.
33 | // For more info see:
34 | // https://developer.algorand.org/docs/reference/transactions/#payment-transaction
35 |
36 | // Sign the transaction
37 | let signedTxn = txn.signTxn(myAccount.sk);
38 | let txId = txn.txID().toString();
39 | console.log("Signed transaction with txID: %s", txId);
40 |
41 | // Submit the transaction
42 | await algodClient.sendRawTransaction(signedTxn).do();
43 |
44 | // Wait for confirmation
45 | let confirmedTxn = await algosdk.waitForConfirmation(algodClient, txId, 4);
46 | //Get the completed Transaction
47 | console.log("Transaction " + txId + " confirmed in round " + confirmedTxn["confirmed-round"]);
48 | var string = new TextDecoder().decode(confirmedTxn.txn.txn.note);
49 | console.log("Note field: ", string);
50 | accountInfo = await algodClient.accountInformation(myAccount.addr).do();
51 | console.log("Transaction Amount: %d microAlgos", confirmedTxn.txn.txn.amt);
52 | console.log("Transaction Fee: %d microAlgos", confirmedTxn.txn.txn.fee);
53 | let closeoutamt = startingAmount - confirmedTxn.txn.txn.amt - confirmedTxn.txn.txn.fee;
54 | console.log("Close To Amount: %d microAlgos", closeoutamt);
55 | console.log("Account balance: %d microAlgos", accountInfo.amount);
56 | }
57 | catch (err) {
58 | console.log("err", err);
59 | }
60 | process.exit();
61 | };
62 |
63 | firstTransaction();
--------------------------------------------------------------------------------
/front_end/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Create React App
2 |
3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4 |
5 | ## Available Scripts
6 |
7 | In the project directory, you can run:
8 |
9 | ### `npm start`
10 |
11 | Runs the app in the development mode.\
12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
13 |
14 | The page will reload when you make changes.\
15 | You may also see any lint errors in the console.
16 |
17 | ### `npm test`
18 |
19 | Launches the test runner in the interactive watch mode.\
20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21 |
22 | ### `npm run build`
23 |
24 | Builds the app for production to the `build` folder.\
25 | It correctly bundles React in production mode and optimizes the build for the best performance.
26 |
27 | The build is minified and the filenames include the hashes.\
28 | Your app is ready to be deployed!
29 |
30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31 |
32 | ### `npm run eject`
33 |
34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!**
35 |
36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37 |
38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
39 |
40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
41 |
42 | ## Learn More
43 |
44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45 |
46 | To learn React, check out the [React documentation](https://reactjs.org/).
47 |
48 | ### Code Splitting
49 |
50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51 |
52 | ### Analyzing the Bundle Size
53 |
54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55 |
56 | ### Making a Progressive Web App
57 |
58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59 |
60 | ### Advanced Configuration
61 |
62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63 |
64 | ### Deployment
65 |
66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67 |
68 | ### `npm run build` fails to minify
69 |
70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
71 |
--------------------------------------------------------------------------------
/webapps/views_pages.py:
--------------------------------------------------------------------------------
1 | from flask import Blueprint, render_template, redirect, url_for
2 | from flask_login import login_required, logout_user, current_user
3 |
4 | from .forms import SendForm, AssetForm, FilterForm
5 | #update view all pages
6 | main_bp = Blueprint(
7 | 'main_bp', __name__,
8 | template_folder='frontend_page',
9 | static_folder='css_file'
10 | )
11 |
12 |
13 | @main_bp.route('/')
14 | @login_required
15 | def index():
16 | """Main page, displays balance"""
17 | balance = current_user.get_balance()
18 | return render_template('index.html', balance=balance)
19 |
20 |
21 | @main_bp.route('/send', methods=['GET', 'POST'])
22 | @login_required
23 | def send():
24 | """Provides a form to create and send a transaction"""
25 | form = SendForm()
26 | address = current_user.public_key
27 | if form.validate_on_submit():
28 | success = current_user.send(form.quantity.data, form.receiver.data, form.note.data)
29 | return render_template('success.html', success=success)
30 |
31 | # show the form, it wasn't submitted
32 | return render_template('send.html', form=form, address=address)
33 |
34 |
35 | @main_bp.route('/nft', methods=['GET', 'POST'])
36 | @login_required
37 | def nft():
38 | """Provides a form to post and view the certeficate"""
39 | form = SendForm()
40 | address = current_user.public_key
41 | if form.validate_on_submit():
42 | success = current_user.send(form.quantity.data, form.receiver.data, form.note.data)
43 | return render_template('success.html', success=success)
44 |
45 | # show the form, it wasn't submitted
46 | return render_template('nft.html', form=form, address=address)
47 |
48 |
49 | @main_bp.route('/create', methods=['GET', 'POST'])
50 | @login_required
51 | def create():
52 | """Provides a form to create an asset"""
53 | form = AssetForm()
54 | if form.validate_on_submit():
55 | success = current_user.create(
56 | form.asset_name.data,
57 | form.unit_name.data,
58 | form.total.data,
59 | form.decimals.data,
60 | form.default_frozen.data,
61 | form.url.data
62 | )
63 |
64 | print(success)
65 | return redirect(url_for('main_bp.assets'))
66 |
67 | # show the form, it wasn't submitted
68 | return render_template('create_asset.html', form=form)
69 |
70 |
71 | @main_bp.route('/transactions', methods=['GET', 'POST'])
72 | @login_required
73 | def transactions():
74 | """Displays all transactions from the user"""
75 | form = FilterForm()
76 |
77 | if form.validate_on_submit():
78 | txns = current_user.get_transactions(form.substring.data)
79 | else:
80 | txns = current_user.get_transactions("")
81 |
82 | return render_template('transactions.html', txns=txns, form=form)
83 |
84 |
85 | @main_bp.route('/assets', methods=['GET', 'POST'])
86 | @login_required
87 | def assets():
88 | """Displays all assets owned by the user"""
89 | form = FilterForm()
90 |
91 | if form.validate_on_submit():
92 | assets_list = current_user.get_assets(form.substring.data)
93 | else:
94 | assets_list = current_user.get_assets("")
95 |
96 | return render_template('assets.html', assets=assets_list, form=form)
97 |
98 |
99 | @main_bp.route('/mnemonic')
100 | @login_required
101 | def mnemonic():
102 | """Displays the recovery passphrase"""
103 | passphrase = current_user.passphrase
104 | return render_template('mnemonic.html', passphrase=passphrase)
105 |
106 |
107 | @main_bp.route('/logout')
108 | @login_required
109 | def logout():
110 | """User log-out logic."""
111 | logout_user()
112 | return redirect(url_for('auth_bp.login'))
113 |
--------------------------------------------------------------------------------
/webapps/algodand.py:
--------------------------------------------------------------------------------
1 | from algosdk import account, mnemonic
2 | from algosdk.constants import microalgos_to_algos_ratio
3 | from algosdk.future.transaction import PaymentTxn, AssetConfigTxn
4 | from algosdk.v2client import algod
5 |
6 | #algorand account
7 | def algod_client():
8 | """Initialise and return an algod client"""
9 |
10 | algod_address = "https://testnet-algorand.api.purestake.io/ps2"
11 |
12 | algod_token = "XycLijM8J6aGrHCed8Tld3hNKfHFxWpF9eQ1d2gQ"
13 | headers = {
14 | "X-API-Key": algod_token,
15 | }
16 |
17 | return algod.AlgodClient(algod_token, algod_address, headers)
18 |
19 |
20 | def create_account():
21 | """Create account and return its mnemonic"""
22 |
23 | private_key, address = account.generate_account()
24 | return mnemonic.from_private_key(private_key)
25 |
26 |
27 | def get_balance(address):
28 | """Returns the given address balance in algos converted from microalgos"""
29 | account_info = algod_client().account_info(address)
30 | balance = account_info.get('amount') / microalgos_to_algos_ratio
31 |
32 | return balance
33 |
34 |
35 | def send_txn(sender, quantity, receiver, note, sk):
36 | """Create and sign a transaction. Quantity is assumed to be in algorands, not microalgos"""
37 |
38 | quantity = int(quantity * microalgos_to_algos_ratio)
39 | params = algod_client().suggested_params()
40 | note = note.encode()
41 | try:
42 | unsigned_txn = PaymentTxn(sender, params, receiver, quantity, None, note)
43 | except Exception as err:
44 | print(err)
45 | return False
46 | signed_txn = unsigned_txn.sign(sk)
47 | try:
48 | txid = algod_client().send_transaction(signed_txn)
49 | except Exception as err:
50 | print(err)
51 | return False
52 |
53 | # wait for confirmation
54 | try:
55 | wait_for_confirmation(txid, 4)
56 | return True
57 | except Exception as err:
58 | print(err)
59 | return False
60 |
61 |
62 | # utility for waiting on a transaction confirmation
63 | def wait_for_confirmation(transaction_id, timeout):
64 | start_round = algod_client().status()["last-round"] + 1
65 | current_round = start_round
66 |
67 | while current_round < start_round + timeout:
68 | try:
69 | pending_txn = algod_client().pending_transaction_info(transaction_id)
70 | except Exception as err:
71 | print(err)
72 | return
73 | if pending_txn.get("confirmed-round", 0) > 0:
74 | return pending_txn
75 | elif pending_txn["pool-error"]:
76 | raise Exception(
77 | 'pool error: {}'.format(pending_txn["pool-error"]))
78 | algod_client().status_after_block(current_round)
79 | current_round += 1
80 | raise Exception(
81 | 'pending tx not found in timeout rounds, timeout value = : {}'.format(timeout))
82 |
83 |
84 | def create_asset(
85 | creator,
86 | asset_name,
87 | unit_name,
88 | total,
89 | decimals,
90 | default_frozen,
91 | url,
92 | sk
93 | ):
94 | """Creates an asset, returns the newly created asset ID"""
95 | params = algod_client().suggested_params()
96 |
97 | txn = AssetConfigTxn(
98 | sender=creator,
99 | sp=params,
100 | total=total,
101 | default_frozen=default_frozen,
102 | unit_name=unit_name,
103 | asset_name=asset_name,
104 | manager=creator,
105 | reserve=creator,
106 | freeze=creator,
107 | clawback=creator,
108 | url=url,
109 | decimals=decimals)
110 |
111 | # Sign with secret key of creator
112 | stxn = txn.sign(sk)
113 |
114 | # Send the transaction to the network and retrieve the txid.
115 | txid = algod_client().send_transaction(stxn)
116 |
117 | try:
118 | wait_for_confirmation(txid, 4)
119 | except Exception as err:
120 | print(err)
121 | return None
122 |
123 | try:
124 | ptx = algod_client().pending_transaction_info(txid)
125 | asset_id = ptx["asset-index"]
126 | return asset_id
127 | except Exception as err:
128 | print(err)
129 | return None
130 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2022 Birhanu Gebisa, 10 Academy
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/Notebooks/first_transaction.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "Algorand Blockchain Technology"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": 1,
13 | "metadata": {},
14 | "outputs": [
15 | {
16 | "name": "stdout",
17 | "output_type": "stream",
18 | "text": [
19 | "My address: H7PIIHQV2QGPBSY5VOM2F7A354IVACDB5BKQZQ3RB2BETEQ3NN5TTGC5XY\n",
20 | "My passphrase: piece pause multiply stay stuff country prepare melt spray helmet label refuse hunt number skull jar cute safe put profit flower true secret above extra\n"
21 | ]
22 | }
23 | ],
24 | "source": [
25 | "from algosdk import account, mnemonic\n",
26 | "#update algorand\n",
27 | "private_key, address = account.generate_account()\n",
28 | "print(\"My address: {}\".format(address))\n",
29 | "#print(\"My private key: {}\".format(private_key))\n",
30 | "print(\"My passphrase: {}\".format(mnemonic.from_private_key(private_key)))"
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": 2,
36 | "metadata": {},
37 | "outputs": [
38 | {
39 | "name": "stdout",
40 | "output_type": "stream",
41 | "text": [
42 | "Private key from mnemonic: LrEKSP07AqKxf5G4N1CBBZsc6IBNrzaW7GEw4yGZ+0jwR3oUFNy9rTb0AaYEbrbPUTNyzfRLUH8GXyH+oJzJZw==\n",
43 | "Public key from mnemonic: 6BDXUFAU3S622NXUAGTAI3VWZ5ITG4WN6RFVA7YGL4Q75IE4ZFT6GJWZOI\n"
44 | ]
45 | }
46 | ],
47 | "source": [
48 | "#print(f\"Private key from mnemonic: {mnemonic.to_private_key('chair client piano save afford hammer work multiply warfare dolphin scheme raccoon decrease deliver hire quantum short rather couch credit duck town elephant able invite')}\")\n",
49 | "print(f\"Public key from mnemonic: {mnemonic.to_public_key('chair client piano save afford hammer work multiply warfare dolphin scheme raccoon decrease deliver hire quantum short rather couch credit duck town elephant able invite')}\")"
50 | ]
51 | },
52 | {
53 | "cell_type": "code",
54 | "execution_count": 7,
55 | "metadata": {},
56 | "outputs": [
57 | {
58 | "name": "stdout",
59 | "output_type": "stream",
60 | "text": [
61 | "Account balance: 0 microAlgos\n",
62 | "\n"
63 | ]
64 | }
65 | ],
66 | "source": [
67 | "account_info = algod_client.account_info(address)\n",
68 | "print(\"Account balance: {} microAlgos\".format(account_info.get('amount')) + \"\\n\")"
69 | ]
70 | },
71 | {
72 | "cell_type": "code",
73 | "execution_count": 9,
74 | "metadata": {},
75 | "outputs": [],
76 | "source": [
77 | "mnemo_2 = 'emerge quarter always side worry table glow twelve divorce prize income whisper knife brave mention bench monitor march wait throw glue cover photo abandon arctic'\n",
78 | "priv_2 = mnemonic.to_private_key(mnemo_2)\n",
79 | "pub_2 = mnemonic.to_public_key(mnemo_2)"
80 | ]
81 | },
82 | {
83 | "cell_type": "code",
84 | "execution_count": 10,
85 | "metadata": {},
86 | "outputs": [
87 | {
88 | "data": {
89 | "text/plain": [
90 | "'3QVNU6X57L35WGLR2WATU4XHRENJNWYSR54WVGQORYFSGM3JTTWISW6BLA'"
91 | ]
92 | },
93 | "execution_count": 10,
94 | "metadata": {},
95 | "output_type": "execute_result"
96 | }
97 | ],
98 | "source": [
99 | "pub_2"
100 | ]
101 | },
102 | {
103 | "cell_type": "code",
104 | "execution_count": 11,
105 | "metadata": {},
106 | "outputs": [],
107 | "source": [
108 | "from algosdk.v2client import algod\n",
109 | "\n",
110 | "algod_address = \"http://localhost:4001\"\n",
111 | "algod_token = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n",
112 | "algod_client = algod.AlgodClient(algod_token, algod_address)"
113 | ]
114 | },
115 | {
116 | "cell_type": "code",
117 | "execution_count": 12,
118 | "metadata": {},
119 | "outputs": [
120 | {
121 | "name": "stdout",
122 | "output_type": "stream",
123 | "text": [
124 | "Account balance: 4495000 microAlgos\n",
125 | "\n"
126 | ]
127 | }
128 | ],
129 | "source": [
130 | "account_info = algod_client.account_info(pub_2)\n",
131 | "print(\"Account balance: {} microAlgos\".format(account_info.get('amount')) + \"\\n\")"
132 | ]
133 | },
134 | {
135 | "cell_type": "code",
136 | "execution_count": 13,
137 | "metadata": {},
138 | "outputs": [],
139 | "source": [
140 | "# build transaction\n",
141 | "from algosdk.future import transaction\n",
142 | "from algosdk import constants\n",
143 | "\n",
144 | "\n",
145 | "params = algod_client.suggested_params()\n",
146 | "# comment out the next two (2) lines to use suggested fees\n",
147 | "params.flat_fee = True\n",
148 | "params.fee = constants.MIN_TXN_FEE \n",
149 | "receiver = address\n",
150 | "note = \"Hello World\".encode()\n",
151 | "amount = 1000000\n",
152 | "unsigned_txn = transaction.PaymentTxn(pub_2, params, receiver, amount, None, note)"
153 | ]
154 | },
155 | {
156 | "cell_type": "code",
157 | "execution_count": 14,
158 | "metadata": {},
159 | "outputs": [],
160 | "source": [
161 | "# sign transaction\n",
162 | "signed_txn = unsigned_txn.sign(priv_2)"
163 | ]
164 | },
165 | {
166 | "cell_type": "code",
167 | "execution_count": 15,
168 | "metadata": {},
169 | "outputs": [],
170 | "source": [
171 | "txid = algod_client.send_transaction(signed_txn)"
172 | ]
173 | },
174 | {
175 | "cell_type": "code",
176 | "execution_count": 16,
177 | "metadata": {},
178 | "outputs": [
179 | {
180 | "name": "stdout",
181 | "output_type": "stream",
182 | "text": [
183 | "Successfully sent transaction with txID: NQ6JNWZOFKG3FD5QTBDK5OH22JANFLOBLWNRBBRJ7GKBZISVKKXA\n",
184 | "Transaction information: {\n",
185 | " \"confirmed-round\": 24488954,\n",
186 | " \"pool-error\": \"\",\n",
187 | " \"txn\": {\n",
188 | " \"sig\": \"JHuOj6QYMM1pbom4y6C3vD934OrZhqdfaWSV7Xmj17yTzrkG2hVMzKnNsXiOISViLtm4l4a92XAr9ypQAGhABQ==\",\n",
189 | " \"txn\": {\n",
190 | " \"amt\": 1000000,\n",
191 | " \"fee\": 1000,\n",
192 | " \"fv\": 24488951,\n",
193 | " \"gen\": \"testnet-v1.0\",\n",
194 | " \"gh\": \"SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=\",\n",
195 | " \"lv\": 24489951,\n",
196 | " \"note\": \"SGVsbG8gV29ybGQ=\",\n",
197 | " \"rcv\": \"QWWVT6VAMOH7UPBWFD26NXYQKGAOBJXVVIXF47T2DCFGPZJTUBW4AABG5M\",\n",
198 | " \"snd\": \"3QVNU6X57L35WGLR2WATU4XHRENJNWYSR54WVGQORYFSGM3JTTWISW6BLA\",\n",
199 | " \"type\": \"pay\"\n",
200 | " }\n",
201 | " }\n",
202 | "}\n",
203 | "Decoded note: Hello World\n",
204 | "Starting Account balance: 4495000 microAlgos\n",
205 | "Amount transfered: 1000000 microAlgos\n",
206 | "Fee: 1000 microAlgos\n",
207 | "Final Account balance: 3494000 microAlgos\n",
208 | "\n"
209 | ]
210 | }
211 | ],
212 | "source": [
213 | "import json\n",
214 | "import base64\n",
215 | "\n",
216 | "\n",
217 | "#submit transaction\n",
218 | "\n",
219 | "print(\"Successfully sent transaction with txID: {}\".format(txid))\n",
220 | "\n",
221 | "# wait for confirmation \n",
222 | "try:\n",
223 | " confirmed_txn = transaction.wait_for_confirmation(algod_client, txid, 4) \n",
224 | "except Exception as err:\n",
225 | " print(err)\n",
226 | " # return\n",
227 | "\n",
228 | "print(\"Transaction information: {}\".format(\n",
229 | " json.dumps(confirmed_txn, indent=4)))\n",
230 | "print(\"Decoded note: {}\".format(base64.b64decode(\n",
231 | " confirmed_txn[\"txn\"][\"txn\"][\"note\"]).decode()))\n",
232 | "print(\"Starting Account balance: {} microAlgos\".format(account_info.get('amount')) )\n",
233 | "print(\"Amount transfered: {} microAlgos\".format(amount) ) \n",
234 | "print(\"Fee: {} microAlgos\".format(params.fee) ) \n",
235 | "\n",
236 | "\n",
237 | "account_info = algod_client.account_info(pub_2)\n",
238 | "print(\"Final Account balance: {} microAlgos\".format(account_info.get('amount')) + \"\\n\")"
239 | ]
240 | },
241 | {
242 | "cell_type": "code",
243 | "execution_count": 17,
244 | "metadata": {},
245 | "outputs": [
246 | {
247 | "name": "stdout",
248 | "output_type": "stream",
249 | "text": [
250 | "Account balance: 1000000 microAlgos\n",
251 | "\n"
252 | ]
253 | }
254 | ],
255 | "source": [
256 | "account_info = algod_client.account_info(address)\n",
257 | "print(\"Account balance: {} microAlgos\".format(account_info.get('amount')) + \"\\n\")"
258 | ]
259 | },
260 | {
261 | "cell_type": "code",
262 | "execution_count": 18,
263 | "metadata": {},
264 | "outputs": [],
265 | "source": [
266 | "from algosdk.future.transaction import AssetConfigTxn, AssetTransferTxn, AssetFreezeTxn, wait_for_confirmation"
267 | ]
268 | },
269 | {
270 | "cell_type": "code",
271 | "execution_count": 19,
272 | "metadata": {},
273 | "outputs": [
274 | {
275 | "name": "stdout",
276 | "output_type": "stream",
277 | "text": [
278 | "Signed transaction with txID: ZN7XMSBB3RVXKUFANSRUJ4Q5I53FSS5UXTPGO2V3ZPNPQQWN5VCQ\n",
279 | "TXID: ZN7XMSBB3RVXKUFANSRUJ4Q5I53FSS5UXTPGO2V3ZPNPQQWN5VCQ\n",
280 | "Result confirmed in round: 24488976\n",
281 | "Transaction information: {\n",
282 | " \"asset-index\": 113929434,\n",
283 | " \"confirmed-round\": 24488976,\n",
284 | " \"pool-error\": \"\",\n",
285 | " \"txn\": {\n",
286 | " \"sig\": \"GlpKSAEu9ftxGugt3+djiHLH4PjCcorQG+e8ncppEeGFGmTt4GdDAEoswLbXT4j7cyCUwH7TZ6/KI89hoEbOAw==\",\n",
287 | " \"txn\": {\n",
288 | " \"apar\": {\n",
289 | " \"an\": \"10_academy\",\n",
290 | " \"au\": \"https://path/to/my/asset/details\",\n",
291 | " \"c\": \"3QVNU6X57L35WGLR2WATU4XHRENJNWYSR54WVGQORYFSGM3JTTWISW6BLA\",\n",
292 | " \"f\": \"3QVNU6X57L35WGLR2WATU4XHRENJNWYSR54WVGQORYFSGM3JTTWISW6BLA\",\n",
293 | " \"m\": \"3QVNU6X57L35WGLR2WATU4XHRENJNWYSR54WVGQORYFSGM3JTTWISW6BLA\",\n",
294 | " \"r\": \"3QVNU6X57L35WGLR2WATU4XHRENJNWYSR54WVGQORYFSGM3JTTWISW6BLA\",\n",
295 | " \"t\": 1,\n",
296 | " \"un\": \"10\"\n",
297 | " },\n",
298 | " \"fee\": 1000,\n",
299 | " \"fv\": 24488973,\n",
300 | " \"gen\": \"testnet-v1.0\",\n",
301 | " \"gh\": \"SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=\",\n",
302 | " \"lv\": 24489973,\n",
303 | " \"snd\": \"3QVNU6X57L35WGLR2WATU4XHRENJNWYSR54WVGQORYFSGM3JTTWISW6BLA\",\n",
304 | " \"type\": \"acfg\"\n",
305 | " }\n",
306 | " }\n",
307 | "}\n"
308 | ]
309 | }
310 | ],
311 | "source": [
312 | "# CREATE ASSET\n",
313 | "# Get network params for transactions before every transaction.\n",
314 | "params = algod_client.suggested_params()\n",
315 | "# comment these two lines if you want to use suggested params\n",
316 | "# params.fee = 1000\n",
317 | "# params.flat_fee = True\n",
318 | "# Account 1 creates an asset called latinum and\n",
319 | "# sets Account 2 as the manager, reserve, freeze, and clawback address.\n",
320 | "# Asset Creation transaction\n",
321 | "txn = AssetConfigTxn(\n",
322 | " sender=pub_2,\n",
323 | " sp=params,\n",
324 | " total=1,\n",
325 | " default_frozen=False,\n",
326 | " unit_name=\"10\",\n",
327 | " asset_name=\"10_academy\",\n",
328 | " manager=pub_2,\n",
329 | " reserve=pub_2,\n",
330 | " freeze=pub_2,\n",
331 | " clawback=pub_2,\n",
332 | " url=\"https://path/to/my/asset/details\", \n",
333 | " decimals=0)\n",
334 | "# Sign with secret key of creator\n",
335 | "stxn = txn.sign(priv_2)\n",
336 | "# Send the transaction to the network and retrieve the txid.\n",
337 | "try:\n",
338 | " txid = algod_client.send_transaction(stxn)\n",
339 | " print(\"Signed transaction with txID: {}\".format(txid))\n",
340 | " # Wait for the transaction to be confirmed\n",
341 | " confirmed_txn = wait_for_confirmation(algod_client, txid, 4) \n",
342 | " print(\"TXID: \", txid)\n",
343 | " print(\"Result confirmed in round: {}\".format(confirmed_txn['confirmed-round'])) \n",
344 | "except Exception as err:\n",
345 | " print(err)\n",
346 | "# Retrieve the asset ID of the newly created asset by first\n",
347 | "# ensuring that the creation transaction was confirmed,\n",
348 | "# then grabbing the asset id from the transaction.\n",
349 | "print(\"Transaction information: {}\".format(\n",
350 | " json.dumps(confirmed_txn, indent=4)))\n",
351 | "# print(\"Decoded note: {}\".format(base64.b64decode(\n",
352 | "# confirmed_txn[\"txn\"][\"txn\"][\"note\"]).decode()))\n"
353 | ]
354 | },
355 | {
356 | "cell_type": "code",
357 | "execution_count": null,
358 | "metadata": {},
359 | "outputs": [],
360 | "source": []
361 | }
362 | ],
363 | "metadata": {
364 | "kernelspec": {
365 | "display_name": "Python 3.8.13 ('venv')",
366 | "language": "python",
367 | "name": "python3"
368 | },
369 | "language_info": {
370 | "codemirror_mode": {
371 | "name": "ipython",
372 | "version": 3
373 | },
374 | "file_extension": ".py",
375 | "mimetype": "text/x-python",
376 | "name": "python",
377 | "nbconvert_exporter": "python",
378 | "pygments_lexer": "ipython3",
379 | "version": "3.8.13"
380 | },
381 | "orig_nbformat": 4,
382 | "vscode": {
383 | "interpreter": {
384 | "hash": "beb26789953ddcd0d4fafde83f340bee23aa0884c59e24dddb82f7574d20d741"
385 | }
386 | }
387 | },
388 | "nbformat": 4,
389 | "nbformat_minor": 2
390 | }
391 |
--------------------------------------------------------------------------------