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 BuyerPrerequisites
- Completed Hardware Registration, Dataset Registration, or AI Model Registration tutorials
- Completed Role Management tutorial
- Understanding of Rewards and Tokens
SELLER_ROLEfor selling resources (see Role Management)BUYER_ROLEfor purchasing resources (see Role Management)- Understanding of Rewards and Tokens
- Tokens for purchasing (see Rewards tutorial)
Required Roles
Marketplace Roles
The marketplace requires specific roles for different operations:
| Role | Purpose | Required For |
|---|---|---|
SELLER_ROLE | List resources for sale | Listing hardware, datasets, or AI models |
BUYER_ROLE | Purchase listed resources | Buying resources with tokens |
MARKETPLACE_OPERATOR_ROLE | Manage marketplace operations | Removing listings, pausing marketplace (admin only) |
Authorization
To list resources for sale:
- Your identity must have
SELLER_ROLE(granted byADMIN_ROLE) - You must own the resource being listed
To purchase resources:
- Your identity must have
BUYER_ROLE(granted byADMIN_ROLE) - You must have sufficient tokens
- You cannot buy your own resources
To manage marketplace:
- Your identity must have
MARKETPLACE_OPERATOR_ROLE(granted byADMIN_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/sellRequest
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
| Field | Type | Required | Description |
|---|---|---|---|
walletId | string | Yes | Your wallet ID |
password | string | Yes | Wallet password |
seller | string | Yes | Your identity DID (resource owner, format: did:ethr:{network}:0x...) |
resourceId | string | Yes | Resource ID to sell |
price | number | Yes | Price in tokens (non-negative integer) |
resourceType | string | Yes | "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
| Code | Error | Cause |
|---|---|---|
| 404 | WALLET_NOT_FOUND | Wallet doesn’t exist |
| 400 | WRONG_PASSWORD | Wallet password incorrect |
| 400 | INVALID_SELLER | Seller identity format invalid |
| 400 | INVALID_RESOURCE | Resource ID empty |
| 400 | INVALID_PRICE | Price negative |
| 400 | RESOURCE_ALREADY_ON_SALE | Resource already listed |
| 403 | INVALID_WALLET | Wallet doesn’t belong to you |
| 500 | TRANSACTION_ERROR | Blockchain 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
| Field | Description |
|---|---|
id | Listing ID |
resourceId | Resource being sold |
price | Price in tokens |
resourceType | Type of resource |
buyer | Buyer identity (0x000… if not yet purchased) |
bought | Purchase status |
created | Listing creation timestamp |
boughtDate | Purchase timestamp (0 if not purchased) |
Step 3: Purchase Resource
Buy a listed resource with tokens.
Endpoint
POST /api/v1/marketplace/buyRequest
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
| Field | Type | Required | Description |
|---|---|---|---|
walletId | string | Yes | Your wallet ID |
password | string | Yes | Wallet password |
buyer | string | Yes | Your identity DID (buyer, format: did:ethr:{network}:0x...) |
listedResourceId | string | Yes | Listing ID from marketplace |
Response (200 OK)
{}Transaction Steps
The purchase process:
- Verify buyer has sufficient tokens
- Deduct tokens from buyer
- Transfer tokens to seller
- Transfer resource ownership to buyer
- Mark listing as purchased
- Grant buyer full access to resource
Error Responses
| Code | Error | Cause |
|---|---|---|
| 404 | WALLET_NOT_FOUND | Wallet doesn’t exist |
| 404 | LISTED_RESOURCE_NOT_FOUND | Listing doesn’t exist |
| 400 | WRONG_PASSWORD | Wallet password incorrect |
| 400 | INVALID_BUYER | Buyer identity format invalid |
| 400 | LISTED_RESOURCE_ALREADY_BOUGHT | Resource already purchased |
| 403 | INVALID_WALLET | Wallet doesn’t belong to you |
| 500 | TRANSACTION_ERROR | Blockchain 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/marketplaceRequest
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
| Field | Type | Required | Description |
|---|---|---|---|
walletId | string | Yes | Your wallet ID |
password | string | Yes | Wallet password |
userDID | string | Yes | Your identity DID (must have MARKETPLACE_OPERATOR_ROLE) |
listedResourceId | string | Yes | Listing ID to remove |
Response (200 OK)
{}Error Responses
| Code | Error | Cause |
|---|---|---|
| 404 | WALLET_NOT_FOUND | Wallet doesn’t exist |
| 404 | LISTED_RESOURCE_NOT_FOUND | Listing doesn’t exist |
| 400 | WRONG_PASSWORD | Wallet password incorrect |
| 400 | INVALID_USER_DID | User DID format invalid |
| 403 | MARKETPLACE_OPERATOR_ROLE_REQUIRED | Missing required role |
| 403 | INVALID_WALLET | Wallet doesn’t belong to you |
| 500 | TRANSACTION_ERROR | Blockchain transaction failed |
Note: You can only remove listings you created that haven’t been purchased yet.
Next Steps
- Rewards and Tokens - Manage tokens and earn rewards
Related Topics
- Hardware Registration - Register hardware to sell
- Dataset Registration - Register datasets to sell
- AI Model Registration - Register models to sell
- Resource Access Control - Access transfers with ownership