Andamio Logo
Protocol/Protocol V2/Transaction State Machine/Course

Manage Teachers

API integration guide for adding and removing teachers from an Andamio course

Manage Teachers

Course owners can add or remove teachers from an existing course. This transaction updates the on-chain teacher list and syncs the full list to the database, replacing the previous set entirely.

Summary

PropertyValue
SystemCourse
RoleOwner
Type Keyteachers_update
Build EndpointPOST /api/v2/tx/course/owner/teachers/manage
DB SyncYes
Service Fee10 ADA
Est. Wallet Cost~10.3 ADA

The estimated wallet cost breaks down as: transaction fee ~0.30 ADA + service fee 10 ADA. No additional UTxO deposits are required.

Build Transaction

Endpoint

POST /api/v2/tx/course/owner/teachers/manage

Request Body

{
  "alias": "courseowner",
  "courseId": "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4",
  "teachersToAdd": ["newteacher1", "newteacher2"],
  "teachersToRemove": ["oldteacher"],
  "walletData": {
    "usedAddresses": ["addr1qx2fxv..."],
    "changeAddress": "addr1qx2fxv..."
  }
}
FieldTypeRequiredDescription
aliasstring (Alias)YesThe course owner's access token alias.
courseIdstring (GYMintingPolicyId)YesThe 56-character hex policy ID returned when the course was created.
teachersToAddstring[] (Alias[])YesAliases of teachers to add. Each must have a minted access token. Pass an empty array if not adding anyone.
teachersToRemovestring[] (Alias[])YesAliases of teachers to remove. Pass an empty array if not removing anyone.
walletDataWalletDataNoObject containing usedAddresses (string[]) and changeAddress (string).

Response

{
  "unsignedTxCBOR": "84a800..."
}

The response contains the unsigned transaction CBOR, ready for the user's wallet to sign.

Register Transaction

After the user signs and submits the transaction, register it with the state machine:

POST /api/v2/tx/register

{
  "tx_hash": "64-char hex hash from wallet.submitTx()",
  "tx_type": "teachers_update"
}

No metadata is required. On confirmation, the state machine reads the full teacher list from the on-chain datum and replaces the entire teacher list in the database, ensuring the DB always mirrors the chain.

EndpointDescription
GET /api/v2/courses/{course_id}Verify the updated teacher list after the transaction confirms

Example: Full Lifecycle

const API_URL = "https://api.andamio.io";

// 1. Build
const buildRes = await fetch(`${API_URL}/api/v2/tx/course/owner/teachers/manage`, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": API_KEY,
    "Authorization": `Bearer ${userJwt}`,
  },
  body: JSON.stringify({
    alias: "courseowner",
    courseId: "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4",
    teachersToAdd: ["newteacher1", "newteacher2"],
    teachersToRemove: [],
    walletData: {
      usedAddresses: [walletAddress],
      changeAddress: walletAddress,
    },
  }),
});
const { unsignedTxCBOR } = await buildRes.json();

// 2. Sign
const signedTx = await wallet.signTx(unsignedTxCBOR);

// 3. Submit
const txHash = await wallet.submitTx(signedTx);

// 4. Register
await fetch(`${API_URL}/api/v2/tx/register`, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": API_KEY,
    "Authorization": `Bearer ${userJwt}`,
  },
  body: JSON.stringify({
    tx_hash: txHash,
    tx_type: "teachers_update",
  }),
});

// 5. Monitor (SSE)
const events = new EventSource(
  `${API_URL}/api/v2/tx/stream/${txHash}`
);
events.addEventListener("state_change", (e) => {
  const data = JSON.parse(e.data);
  console.log(`State: ${data.old_state} → ${data.new_state}`);
});
events.addEventListener("complete", (e) => {
  const data = JSON.parse(e.data);
  console.log(`Final: ${data.final_state}`);
  events.close();
});

See Also