Gladius backend cloud functions

Gladius backend functional setup

Club Sign-up

1. create club owner user cloud function


This Firebase function facilitates the sign-up process for the Gladius Club Owner user


- creates an auth record and email and UID

- frontend calling /users collections and waiting for a user doc to appear


- triggers Auth create record and creates doc ( in /users) with stellar wallet

trigger source code

2. set club owner in the contract cloud function

source code


This Firebase function facilitates the sign-up process for the Gladius Club. It integrates with Firebase Firestore for user verification and the Stellar blockchain for role management within a sports club context.


- calls CF SignupGladiusClub

Request Body Parameters

'{ "ClubOwnerUID": "9UY6EVSrd0XDAHFBdt8sRpGsxLw1",

"ClubName" : "Chess club" }'


- receives ClubOwnerUID, ClubName

- creates club doc in /clubs with unique clubUID

- sets the club_name in club doc based on ClubName

- copies stellar wallet public and private keys from /users doc(ClubOwnerUID) to /clubs/{clubUID}

- sets role = “owner” in club_roles under /users doc(ClubOwnerUID)

- executes Gladius contract Soroban function “set_is_sport_club“

Returns: club_owner_UID has been added to club_doc_UID

{ "message": "Club owner [user email] created a club [club public key]",

"club_public_key": "[Club owner's Stellar public key]"}

3.5 add calendar to the club

· Frontend adds a calendar link to a new club doc

Create Course

4. create course cloud function

source code


Handles the creation of a new course within a sports club on the Stellar blockchain, leveraging Firebase Firestore for user authentication and management.


- calls CF SignupGladiusClubCourse

Request Body Parameters (example)

{ "ClubOwnerUID": "MmNNhkPnhXfluJ0HMpwCFFImpLt2",

"ClubUID" : "4",

"CourseName" : "My awesome course",

"CoursePrice" : 200,

"Courseincentive" : 15,

"CourseIndex" : 8 }'


- Ensures required parameters (ClubOwnerUID, ClubUID, CourseName, CoursePrice, Courseincentive) are provided in the request body.

- executes create_course function with provided parameters


{"message":"Club owner [user email] created a club [club public key]","club_public_key":"[Club owner's Stellar public key]"

Signup as Parent

5. add student to club cloud function

source code

Purpose: Manages the role assignment and course subscriptions for students and parents within a sports club ecosystem on the Stellar blockchain, facilitated through Firebase Firestore and Stellar smart contracts.


- creates parent and student Auth record

-> wallets created automatically following logic described in (1)

- calls

Request Body Parameters (example)

{ "StudentUID": "exampleStudentUID",

"ParentUID": "exampleParentUID",

"ClubUID" : "exampleClubUID",

"GroupUID" : "exampleGroupUID",

"StudentPassword" : "exampleStudentPassword" }


- Ensures required inputs (ParentUID, StudentUID, ClubUID, GroupUID) are provided and valid.

- Fetches and verifies necessary data from Firestore (for student, parent, and club)

- Executes contract functions with provided parameters

  • Mints EURC to Parent

    • mintToken(addressBook.getContractId(network, 'token_id'), 200, parent.publicKey(), payment_token_admin);

  • Sets and checks roles for both student and parent

  • Registers and manages course subscriptions

    • invokeContract('gladius_subscriptions_id', addressBook, 'get_course', getCourseParams, sport_club);

    • invokeContract('gladius_subscriptions_id', addressBook, 'subscribe_course', subscribeCourseParams, parent);

  • Returns contract function response

    • Example response

{ "message": "Student was added to club ExampleClub by",




Check balance

6. getStudentBalanceByID

source code


- Request Body Parameters (example)

{ "StudentUID": "exampleStudentUID" }

- Response example

{message: `GLC Balance of ${}`, data: balanceGLCStudent }

Gladius Club NFT

7. fetchGladiusNFT

source core

NFT image is hardcoded at the moment


Retrieves Non-Fungible Tokens (NFTs) associated with a specific user within a sports club environment on the Stellar blockchain, using Firestore to manage user and club data

- Endpoint

-NFT Data Retrieval: Executes a series of blockchain calls to:

  • Get the number of NFTs owned by the user.

  • Fetch each NFT's token ID and associated metadata URI.

  • Retrieve and parse metadata from each URI to compile NFT details.

- Example request

{ "UID": "exampleUserUID"}

- Execute: fetchGladiusNFT(addressBook, user_stellar_secret, club_stellar_secret);

- Return response

{ message: `GLC NFTs of ${}`,

data: fetchGladiusNFTresult });

Example response


"message": "GLC NFTs of",

"data": {

"nfts": [

{ "name": "Gladius Token #1",

"image": "",

"description": "This is a Gladius NFT 1" },

{ "name": "Gladius Token #2",

"image": "",

"description": "This is another Gladius NFT 2" } ]


Gladius coin (GLC) transfer

8. transferGLC

Source code


Facilitates the transfer of Gladius Coins (GLC) between a student's account and a sports club's account on the Stellar blockchain, leveraging Firestore for user and club data management.



User and Club Verification :Checks for necessary parameters (UID and amount), verifying that the amount is a valid number. By default sends GLC to club wallet (this can be changed).

Transaction Execution: Performs several checks before executing the token transfer:

  • Ensures the transaction amount is positive and not zero.

  • Confirms that the sender and receiver are not the same.

  • Verifies that the sender's balance is sufficient to cover the transfer.

  • Executes the transfer on the Stellar blockchain using smart contract interactions.

Example request:

{ "UID": "exampleUserUID", "amount": 100 }

Example response


Cloud function triggers

  • Firebase_auth_sync - triggers Firebase Authentication. Creates user doc from Firebase Auth. Create wallets ( source )

  • Delete_user_document - triggers Firebase Authentication. Deletes user doc when account is deleted from Firebase Auth

  • Firestore_sync_users - triggers Cloud Firestore doc change. Sync clubs_roles field in /users doc and members docs in /clubs ( source )

Future work

Generate images with OpenAI API - could function draft

Last updated