Rarity DTO
Schema for NFT card/rarity definitions used in drop APIs.
Description
The Rarity DTO schema defines the structure of NFT card information including rarity levels, images, and game mechanics values. Used in drop responses and wallet NFT queries.
Class Validator Schema
import { IsNumber, IsOptional, IsString } from "class-validator";
export class RarityDto {
@IsNumber()
rarity: number;
@IsString()
image: string;
@IsString()
@IsOptional()
animation?: string;
@IsNumber()
burnThreshold: number;
@IsString()
name: string;
@IsNumber()
base: number;
@IsNumber()
stack: number;
@IsNumber()
maximum: number;
}
TypeScript Type
interface RarityDto {
rarity: number;
image: string;
animation?: string;
burnThreshold: number;
name: string;
base: number;
stack: number;
maximum: number;
}
Example
{
"rarity": 1,
"image": "https://example.com/common-card.jpg",
"animation": "https://example.com/animation.mp4",
"burnThreshold": 100,
"name": "Common Card",
"base": 50,
"stack": 10,
"maximum": 1000
}
Field Descriptions
Field | Type | Required | Description |
---|---|---|---|
rarity | number | Yes | Rarity level (1 = common, 2 = rare, etc.) |
image | string | Yes | Card image URL |
animation | string | No | Card animation URL (optional) |
burnThreshold | number | Yes | Burn threshold value |
name | string | Yes | Card/rarity name |
base | number | Yes | Base game mechanics value |
stack | number | Yes | Stack game mechanics value |
maximum | number | Yes | Maximum game mechanics value |
Example Response
{
"id": "rarity-1",
"name": "Common",
"probability": 0.7,
"maxSupply": 7000
}
Field Descriptions
Field | Type | Required | Description |
---|---|---|---|
id | string | Yes | Unique identifier for the rarity tier |
name | string | Yes | Human-readable rarity name |
probability | number | Yes | Probability of minting this rarity (0-1) |
maxSupply | number | Yes | Maximum number of NFTs for this rarity tier |
Common Rarity Tiers
Typical rarity tier names include:
- Common: Most frequent, highest probability
- Uncommon: Less frequent than common
- Rare: Uncommon, lower probability
- Epic: Very rare, low probability
- Legendary: Extremely rare, lowest probability
Usage Example
// Example rarity configuration
const rarityTiers = [
{
id: "rarity-1",
name: "Common",
probability: 0.7,
maxSupply: 7000,
},
{
id: "rarity-2",
name: "Uncommon",
probability: 0.2,
maxSupply: 2000,
},
{
id: "rarity-3",
name: "Rare",
probability: 0.08,
maxSupply: 800,
},
{
id: "rarity-4",
name: "Epic",
probability: 0.015,
maxSupply: 150,
},
{
id: "rarity-5",
name: "Legendary",
probability: 0.005,
maxSupply: 50,
},
];
// Validate probabilities sum to 1
const totalProbability = rarityTiers.reduce((sum, tier) => sum + tier.probability, 0);
console.log("Total probability:", totalProbability); // Should be 1.0
Validation Rules
- probability: Must be between 0 and 1
- maxSupply: Must be a positive integer
- id: Must be a unique string identifier
- name: Must be a non-empty string
Related Schemas
- Drop DTO - Main drop structure that contains rarity tiers
- Create Drop Request - Creating drops with rarity tiers
- API Schemas Overview