BB-402 Token-Gated Access
Last updated
Token-gated access protocol where ownership of specific badges grants API/resource access
Category: Features
Protocol for token-gated access to APIs/resources using HTTP 402 Payment Required.
Flow: client requests resource -> server returns 402 + required badge criteria -> client proves ownership -> server validates via BitBadges API
ownershipRequirements: use $and for "must have all", $or for "must have any"
mustOwnAmounts: { start: 1, end: 1 } = must own at least 1
mustOwnAmounts: { start: 0, end: 0 } = must NOT own (exclusion)
Tiered access: different token IDs = different access levels
Time-bounded access: combine ownershipTimes with subscription tokens
Server-side verification: BitBadgesApi.verifyOwnership() or SIWBB sign-in
BB-402 is a protocol for token-gated access to APIs and digital resources. It uses HTTP 402 Payment Required responses to signal that badge ownership is needed.
Client requests a protected resource
Server responds with HTTP 402 + required badge criteria
Client proves badge ownership (signs a challenge or presents proof)
Server validates ownership via BitBadges API and grants access
Require ownership of a specific badge to access a resource.
Different badge IDs = different access levels.
Token ID 1 = Basic access
Token ID 2 = Premium access
Token ID 3 = Admin access
Use ownershipTimes to restrict access to users who own the badge during specific periods. Combine with subscription tokens for recurring access.
Require badges from multiple collections using $and/$or logic.
Create the gate badge collection: Use NFT, fungible, or subscription patterns
Configure ownership requirements: Define what badges grant what access
Server integration: Use BitBadges API to verify ownership:
BitBadgesApi.verifyOwnership() for programmatic checks
SIWBB sign-in for session-based authentication
Client integration: Handle 402 responses, present proof of ownership
Badge ownership checks are point-in-time β consider caching strategies
For subscription-based access, check ownershipTimes overlap with current time
Use $and for "must have all", $or for "must have any"
mustOwnAmounts: { start: 0, end: 0 } means must NOT own (exclusion)
mustOwnAmounts: { start: 1, end: 1 } means must own at least 1
Last updated
{
"ownershipRequirements": {
"$and": [{
"assets": [{
"chain": "BitBadges",
"collectionId": 123,
"assetIds": [{ "start": 1, "end": 1 }],
"mustOwnAmounts": { "start": 1, "end": 1 },
"ownershipTimes": []
}]
}]
}
}