Skip to content
10.5. Resource Marketplace

10.5. Resource Marketplace

This tutorial covers trading AI resources (hardware, datasets, and models) on the dAIEDGE marketplace using the Middleware’s token economy.

Overview

The marketplace enables:

  • Listing resources for sale
  • Discovering available resources
  • Purchasing resources with tokens
  • Transferring ownership via blockchain
  • Automatic payment processing

Marketplace Flow

1. List Resource for Sale (seller)
   ↓
2. Browse Marketplace (buyer)
   ↓
3. Purchase Resource (buyer pays tokens)
   ↓
4. Ownership Transfer (automatic)
   ↓
5. Access Granted to Buyer

Prerequisites


Required Roles

Marketplace Roles

The marketplace requires specific roles for different operations:

RolePurposeRequired For
SELLER_ROLEList resources for saleListing hardware, datasets, or AI models
BUYER_ROLEPurchase listed resourcesBuying resources with tokens
MARKETPLACE_OPERATOR_ROLEManage marketplace operationsRemoving listings, pausing marketplace (admin only)

Authorization

To list resources for sale:

  • Your identity must have SELLER_ROLE (granted by ADMIN_ROLE)
  • You must own the resource being listed

To purchase resources:

  • Your identity must have BUYER_ROLE (granted by ADMIN_ROLE)
  • You must have sufficient tokens
  • You cannot buy your own resources

To manage marketplace:

  • Your identity must have MARKETPLACE_OPERATOR_ROLE (granted by ADMIN_ROLE)

See the Role Management tutorial to obtain these roles.


Step 1: List Resource for Sale

Put a resource on the marketplace.

Endpoint

POST /api/v1/marketplace/sell

Request

curl -X POST https://middleware-daiedge.bisite.usal.es/api/v1/marketplace/sell \
  -H "Content-Type: application/json" \
  -H "x-session-id: {SESSION_ID}" \
  -d '{
    "walletId": "00000b6e8a4d9f3c7b2e5a1d",
    "password": "WalletPass123!",
    "seller": "did:ethr:development:0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7",
    "resourceId": "0x4e7a9c2d5f8b1c4e7a9d2f5b8c1e4a7d9f2b5c8e1d4f7a9c2e5f8b1d4e7a9c2f",
    "price": 1000,
    "resourceType": "hardware"
  }'

Request Body

FieldTypeRequiredDescription
walletIdstringYesYour wallet ID
passwordstringYesWallet password
sellerstringYesYour identity DID (resource owner, format: did:ethr:{network}:0x...)
resourceIdstringYesResource ID to sell
pricenumberYesPrice in tokens (non-negative integer)
resourceTypestringYes"hardware", "dataset", or "ai_model"

Response (200 OK)

{}

Note: The sell endpoint returns an empty body. To find the listing ID after selling, search the marketplace for your resourceId (see Step 2).

Error Responses

CodeErrorCause
404WALLET_NOT_FOUNDWallet doesn’t exist
400WRONG_PASSWORDWallet password incorrect
400INVALID_SELLERSeller identity format invalid
400INVALID_RESOURCEResource ID empty
400INVALID_PRICEPrice negative
400RESOURCE_ALREADY_ON_SALEResource already listed
403INVALID_WALLETWallet doesn’t belong to you
500TRANSACTION_ERRORBlockchain transaction failed (check you have SELLER_ROLE and own the resource)

Step 2: Browse Marketplace

View all resources available for purchase.

Endpoint

GET /api/v1/marketplace?page={page}

Request

curl -X GET "https://middleware-daiedge.bisite.usal.es/api/v1/marketplace?page=1"

Response (200 OK)

{
  "resources": [
    {
      "id": "00000d8a6b4f9c3e7a2d5b1f",
      "resourceId": "0x1c4e7a9d2f5b8c1e4a7d9f2b5c8e1a4d7f9c2b5e8a1d4f7c9e2b5a8d1f4e7c9e",
      "price": 1000,
      "resourceType": "hardware",
      "buyer": "0x0000000000000000000000000000000000000000",
      "bought": false,
      "created": 1697000000000,
      "boughtDate": 0
    },
    {
      "id": "00000e9b7c5a8d4f6e2a9c1b",
      "resourceId": "0x8a2d5f7c9e1b4a7d9f2c5e8a1d4f7c9e2b5a8d1f4c7e9a2d5f8c1b4e7a9d2f5c",
      "price": 500,
      "resourceType": "ai_model",
      "buyer": "0x8Ba1f109551bD432803012645Ac136ddd64DBA72",
      "bougth": true,
      "created": 1697000100000,
      "boughtDate": 1697100000000
    }
  ],
  "page": 1,
  "totalPages": 5,
  "total": 118
}

Response Fields

FieldDescription
idListing ID
resourceIdResource being sold
pricePrice in tokens
resourceTypeType of resource
buyerBuyer identity (0x000… if not yet purchased)
boughtPurchase status
createdListing creation timestamp
boughtDatePurchase timestamp (0 if not purchased)

Step 3: Purchase Resource

Buy a listed resource with tokens.

Endpoint

POST /api/v1/marketplace/buy

Request

curl -X POST https://middleware-daiedge.bisite.usal.es/api/v1/marketplace/buy \
  -H "Content-Type: application/json" \
  -H "x-session-id: {SESSION_ID}" \
  -d '{
    "walletId": "00000f8c6a3d9e5b7c1f4a2e",
    "password": "BuyerPass123!",
    "buyer": "did:ethr:development:0x8Ba1f109551bD432803012645Ac136ddd64DBA72",
    "listedResourceId": "000010a7d4f9b6c3e8a2d5f1"
  }'

Request Body

FieldTypeRequiredDescription
walletIdstringYesYour wallet ID
passwordstringYesWallet password
buyerstringYesYour identity DID (buyer, format: did:ethr:{network}:0x...)
listedResourceIdstringYesListing ID from marketplace

Response (200 OK)

{}

Transaction Steps

The purchase process:

  1. Verify buyer has sufficient tokens
  2. Deduct tokens from buyer
  3. Transfer tokens to seller
  4. Transfer resource ownership to buyer
  5. Mark listing as purchased
  6. Grant buyer full access to resource

Error Responses

CodeErrorCause
404WALLET_NOT_FOUNDWallet doesn’t exist
404LISTED_RESOURCE_NOT_FOUNDListing doesn’t exist
400WRONG_PASSWORDWallet password incorrect
400INVALID_BUYERBuyer identity format invalid
400LISTED_RESOURCE_ALREADY_BOUGHTResource already purchased
403INVALID_WALLETWallet doesn’t belong to you
500TRANSACTION_ERRORBlockchain transaction failed (check you have BUYER_ROLE and sufficient tokens)

Step 4: Remove Listing

Remove your resource from the marketplace. Requires MARKETPLACE_OPERATOR_ROLE.

Endpoint

DELETE /api/v1/marketplace

Request

curl -X DELETE https://middleware-daiedge.bisite.usal.es/api/v1/marketplace \
  -H "Content-Type: application/json" \
  -H "x-session-id: {SESSION_ID}" \
  -d '{
    "walletId": "000011b8e5a7c2d9f4b6a1e3",
    "password": "WalletPass123!",
    "userDID": "did:ethr:development:0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7",
    "listedResourceId": "000012c9f6b8a4d7e3c5a2f1"
  }'

Request Body

FieldTypeRequiredDescription
walletIdstringYesYour wallet ID
passwordstringYesWallet password
userDIDstringYesYour identity DID (must have MARKETPLACE_OPERATOR_ROLE)
listedResourceIdstringYesListing ID to remove

Response (200 OK)

{}

Error Responses

CodeErrorCause
404WALLET_NOT_FOUNDWallet doesn’t exist
404LISTED_RESOURCE_NOT_FOUNDListing doesn’t exist
400WRONG_PASSWORDWallet password incorrect
400INVALID_USER_DIDUser DID format invalid
403MARKETPLACE_OPERATOR_ROLE_REQUIREDMissing required role
403INVALID_WALLETWallet doesn’t belong to you
500TRANSACTION_ERRORBlockchain transaction failed

Note: You can only remove listings you created that haven’t been purchased yet.


Next Steps

Related Topics