Skip to content
11.5. Rewards and Tokens

11.5. Rewards and Tokens

This tutorial covers the dAIEDGE Middleware DLT token economy, including token balance management, earning rewards, and the rewards system.

Overview

The token system enables:

  • Platform currency for marketplace transactions
  • Reward mechanisms for contributions
  • Incentivizing hardware providers
  • Automated reward distribution
  • Manual reward grants

Prerequisites


Required Roles

Token Management Roles

The token system uses a hierarchical role structure:

RolePurposeCan Be Granted By
TOKEN_ADMIN_ROLEUpdate token metadata, pause/unpause token transfersADMIN_ROLE
TOKEN_MINTER_ROLEMint new tokens, create token supplyTOKEN_ADMIN_ROLE
TOKEN_USER_ROLEBurn owned tokens, reduce token supplyADMIN_ROLE

Rewards Management Roles

The rewards system has three distinct roles:

RolePurposeCan Be Granted By
REWARD_ADMIN_ROLESet/remove reward rules, grant manual rewards, pause/unpause systemADMIN_ROLE
REWARD_DISTRIBUTOR_ROLEDistribute on-chain action rewards automaticallyREWARD_ADMIN_ROLE
ORACLE_ROLEDistribute off-chain action rewards, report external eventsREWARD_ADMIN_ROLE

Authorization

For token minting (Step 2):

  • Your identity must have TOKEN_MINTER_ROLE (granted by TOKEN_ADMIN_ROLE holder)

For reward rules (Step 4):

  • Your identity must have REWARD_ADMIN_ROLE (granted by ADMIN_ROLE)

For manual rewards (Step 5):

  • Your identity must have REWARD_ADMIN_ROLE (granted by ADMIN_ROLE)

For on-chain rewards (Step 6):

  • Your identity must have REWARD_DISTRIBUTOR_ROLE (granted by REWARD_ADMIN_ROLE holder)

For off-chain rewards:

  • Your identity must have ORACLE_ROLE (granted by REWARD_ADMIN_ROLE holder)

See the Role Management tutorial to understand role hierarchies.


Step 1: Check Token Balance

View the token balance for an identity.

Endpoint

GET /api/v1/tokens/balance?did={did}

Request

curl -X GET "https://middleware-daiedge.bisite.usal.es/api/v1/tokens/balance?did=did:ethr:development:0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7"

Response (200 OK)

1000000

Returns the token balance as a number (integer).

Error Responses

CodeErrorCause
400INVALID_DIDIdentity format invalid
500TRANSACTION_ERRORBlockchain query failed

Step 2: Mint Tokens (Admin Only)

Create new tokens and assign to an identity.

Endpoint

POST /api/v1/tokens/mint

Request

curl -X POST https://middleware-daiedge.bisite.usal.es/api/v1/tokens/mint \
  -H "Content-Type: application/json" \
  -H "x-session-id: {SESSION_ID}" \
  -d '{
    "walletId": "000013d7a9f4c6b8e3a1d5f2",
    "password": "AdminPass123!",
    "did": "did:ethr:development:0x8Ba1f109551bD432803012645Ac136ddd64DBA72",
    "amount": "10000"
  }'

Request Body

FieldTypeRequiredDescription
walletIdstringYesAdmin wallet ID
passwordstringYesWallet password
didstringYesMinter DID — must have TOKEN_MINTER_ROLE, also receives the tokens
amountstringYesNumber of tokens to mint (passed as string)

Response (200 OK)

{}

Authorization

Only identities with TOKEN_MINTER_ROLE can mint tokens. This role is granted by TOKEN_ADMIN_ROLE holders.

Error Responses

CodeErrorCause
404WALLET_NOT_FOUNDWallet doesn’t exist
400WRONG_PASSWORDWallet password incorrect
400INVALID_DIDIdentity format invalid
400INVALID_AMOUNTAmount negative
403TOKEN_MINTER_ROLE_REQUIREDDID lacks TOKEN_MINTER_ROLE
403INVALID_WALLETWallet doesn’t belong to you
500TRANSACTION_ERRORBlockchain transaction failed (check you have TOKEN_MINTER_ROLE)

Step 3: View Reward History

Check reward history for an identity.

Endpoint

GET /api/v1/rewards?page={page}&did={did}

Request

curl -X GET "https://middleware-daiedge.bisite.usal.es/api/v1/rewards?page=1&did=did:ethr:development:0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7"

Query Parameters

ParameterTypeRequiredDescription
pagenumberNoPage number (default: 1)
didstringYesIdentity address

Response (200 OK)

{
  "history": [
    {
      "id": "000014e8b6a5d9c7f2e4a1b3",
      "identity": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7",
      "action": "HARDWARE_REGISTRATION",
      "rewardType": "on-chain",
      "amount": 500,
      "created": 1697000000000
    },
    {
      "id": "000015f9c7b6a8d5e3f2a4c1",
      "identity": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7",
      "action": "BENCHMARK_EXECUTION",
      "rewardType": "manual",
      "amount": 1000,
      "created": 1697100000000
    }
  ],
  "page": 1,
  "totalPages": 3,
  "total": 65
}

Response Fields

FieldDescription
idReward record ID
identityRecipient identity
actionAction that triggered reward
rewardTypeReward type: on-chain, off-chain, or manual
amountToken amount awarded
createdTimestamp

Step 4: Set Reward Rule (Admin Only)

Define automatic rewards for specific actions.

Endpoint

POST /api/v1/rewards/set-reward-rule

Request

curl -X POST https://middleware-daiedge.bisite.usal.es/api/v1/rewards/set-reward-rule \
  -H "Content-Type: application/json" \
  -H "x-session-id: {SESSION_ID}" \
  -d '{
    "walletId": "000016a8d7c5f9b3e6a2d4f1",
    "password": "AdminPass123!",
    "userDID": "did:ethr:development:0x6A9c2E5d8F1b4A7c9D2e5F8a1C4d7E9b2A5c8D1f",
    "action": "HARDWARE_REGISTRATION",
    "rewardAmount": 500
  }'

Request Body

FieldTypeRequiredDescription
walletIdstringYesAdmin wallet ID
passwordstringYesWallet password
userDIDstringYesAdmin identity DID (format: did:ethr:{network}:0x...)
actionstringYesAction identifier (max 255 chars)
rewardAmountnumberYesToken reward (non-negative integer)

Common Actions

  • HARDWARE_REGISTRATION - Registering hardware
  • BENCHMARK_EXECUTION - Executing benchmarks
  • DATASET_REGISTRATION - Registering datasets
  • AI_MODEL_REGISTRATION - Registering AI models
  • MARKETPLACE_SALE - Selling resources

Response (200 OK)

{}

Authorization

Only identities with REWARD_ADMIN_ROLE can set reward rules.

Error Responses

CodeErrorCause
404WALLET_NOT_FOUNDWallet doesn’t exist
400WRONG_PASSWORDWallet password incorrect
400INVALID_USER_DIDUser DID format invalid
400INVALID_ACTIONAction empty or > 255 chars
400INVALID_REWARD_AMOUNTReward amount negative
403INVALID_WALLETWallet doesn’t belong to you
500TRANSACTION_ERRORBlockchain transaction failed (check you have REWARD_ADMIN_ROLE)

Step 5: Manual Reward

Grant tokens to an identity for contributions.

Endpoint

POST /api/v1/rewards/reward-manual

Request

curl -X POST https://middleware-daiedge.bisite.usal.es/api/v1/rewards/reward-manual \
  -H "Content-Type: application/json" \
  -H "x-session-id: {SESSION_ID}" \
  -d '{
    "walletId": "000017b9e8d6a4f7c5b3e2a1",
    "password": "AdminPass123!",
    "userDID": "did:ethr:development:0x7B8d1F4c9E2a5D7b9F2c4E8a1D5f7C9e2B4a7D1f",
    "did": "did:ethr:development:0x8Ba1f109551bD432803012645Ac136ddd64DBA72",
    "rewardAmount": 1000
  }'

Request Body

FieldTypeRequiredDescription
walletIdstringYesAdmin wallet ID
passwordstringYesWallet password
userDIDstringYesAdmin identity DID (format: did:ethr:{network}:0x...)
didstringYesRecipient identity DID (format: did:ethr:{network}:0x...)
rewardAmountnumberYesToken amount (non-negative integer)

Response (200 OK)

{}

Authorization

Only identities with REWARD_ADMIN_ROLE can grant manual rewards.

Error Responses

CodeErrorCause
404WALLET_NOT_FOUNDWallet doesn’t exist
400WRONG_PASSWORDWallet password incorrect
400INVALID_USER_DIDUser DID format invalid
400INVALID_DIDRecipient identity format invalid
400INVALID_REWARD_AMOUNTReward amount negative
403INVALID_WALLETWallet doesn’t belong to you
500TRANSACTION_ERRORBlockchain transaction failed (check you have REWARD_ADMIN_ROLE)

Use Cases

  • Exceptional contributions
  • Bug bounties
  • Community initiatives
  • Special promotions
  • Compensation

Step 6: On-Chain Reward

Trigger automatic reward based on predefined rules.

Endpoint

POST /api/v1/rewards/reward-on-chain

Request

curl -X POST https://middleware-daiedge.bisite.usal.es/api/v1/rewards/reward-on-chain \
  -H "Content-Type: application/json" \
  -H "x-session-id: {SESSION_ID}" \
  -d '{
    "walletId": "000018c8a9f7d5e3b6a4c2f1",
    "password": "AdminPass123!",
    "userDID": "did:ethr:development:0x8C2e4A6d9F1b5C7e9A2d4F8b1C5e7A9c2D4f8B1e",
    "did": "did:ethr:development:0x8Ba1f109551bD432803012645Ac136ddd64DBA72",
    "action": "HARDWARE_REGISTRATION"
  }'

Request Body

FieldTypeRequiredDescription
walletIdstringYesAdmin wallet ID
passwordstringYesWallet password
userDIDstringYesAdmin identity DID (format: did:ethr:{network}:0x...)
didstringYesRecipient identity DID (format: did:ethr:{network}:0x...)
actionstringYesAction that triggered reward

Response (200 OK)

{}

Note: The reward amount is determined by the reward rule set for this action.

Authorization

Only identities with REWARD_DISTRIBUTOR_ROLE can distribute on-chain rewards.

Error Responses

CodeErrorCause
404WALLET_NOT_FOUNDWallet doesn’t exist
400WRONG_PASSWORDWallet password incorrect
400INVALID_USER_DIDUser DID format invalid
400INVALID_DIDRecipient identity format invalid
400INVALID_ACTIONAction empty or not found in reward rules
403INVALID_WALLETWallet doesn’t belong to you
500TRANSACTION_ERRORBlockchain transaction failed (check you have REWARD_DISTRIBUTOR_ROLE)

Complete Token Lifecycle

1. Token Minting (Admin)
   → Initial distribution to users

2. Earning Tokens
   → Register resources → Automatic rewards
   → Execute benchmarks → Automatic rewards
   → Manual grants → Admin discretion

3. Using Tokens
   → Purchase resources on marketplace
   → Pay for benchmarking services
   → Access premium features

4. Token Transfer
   → Marketplace transactions
   → Ownership transfers
   → Automated by smart contracts

Related Topics