Writing a backend application
To build a token-gated web application, let’s use the FastAPI web framework:
(.venv) $ cd ../token-gated-smart-contract (.venv) $ mkdir token-gated-backend (.venv) $ cd token-gated-backend (.venv) $ pip install fastapi pyjwt
The full code of the token-gated web application can be found here: https://github.com/PacktPublishing/Hands-On-Blockchain-for-Python-Developers--2nd-Edition/blob/main/chapter_17/token-gated-backend/token_gated_app.py.
Create a file named token_gated_app.py
and add the following code:
from datetime import datetime, timedelta, timezone from string import Template import string import json import secrets import os from typing import Union from ape import Contract from ape import networks from ethpm_types import ContractType from fastapi import Depends, FastAPI, HTTPException, status from fastapi.security import OAuth2PasswordBearer from fastapi.middleware.cors import CORSMiddleware import jwt from pydantic import BaseModel...