16 token id strategy

Overview

The token ID strategy is critical for the semi-fungible credit system. It determines how projects map to credit token IDs and affects traceability, scalability, and operational complexity.

Strategy Options

Mapping:

ProjectRecord tokenId = 101
Credit Units tokenId = 101

Implementation:

// When ProjectRecord is minted
uint256 projectTokenId = projectRegistry.mintProjectRecord(...);

// Credits use the same tokenId
carbonCredit1155.setProjectConfig(projectTokenId, capUnits, ...);
carbonCredit1155.mintCredits(projectTokenId, to, amountUnits);

Advantages:

  • ✅ Easiest to trace and reason about

  • ✅ Direct 1:1 mapping

  • ✅ Simple implementation

  • ✅ Clear project-to-credits relationship

Disadvantages:

  • ❌ One project = one issuance batch

  • ❌ Cannot issue multiple batches per project easily

Use Case: One project record represents one issuance batch (most common for v1).

Option 2: tokenId = hash(projectId + vintage + verifier + methodology)

Mapping:

Implementation:

Advantages:

  • ✅ Supports multiple batches per project

  • ✅ Batch-specific tracking

  • ✅ Flexible issuance model

Disadvantages:

  • ❌ More complex tokenId generation

  • ❌ Requires batch management

  • ❌ Harder to trace without mapping table

Use Case: Multiple issuance batches per project (common in carbon markets).

Option 3: Sequential Token IDs with Mapping

Mapping:

Implementation:

Advantages:

  • ✅ Clear batch separation

  • ✅ Multiple batches per project

  • ✅ Sequential IDs (easier to iterate)

Disadvantages:

  • ❌ Requires mapping tables

  • ❌ More complex queries

  • ❌ Additional gas costs

Use Case: Complex multi-batch scenarios.

Recommendation

For v1: Use Option 1

Rationale:

  • Simplest implementation

  • Easiest to understand and audit

  • Sufficient for most use cases

  • Can upgrade to Option 2 later if needed

For Future: Consider Option 2

When to Upgrade:

  • Need multiple issuance batches per project

  • Different vintages need separate tracking

  • Different verifiers/methodologies per project

Implementation Example (Option 1)

ProjectRegistry

CarbonCredit1155

Usage

1

Mint ProjectRecord

2

Configure credits (same tokenId)

3

Mint credits (same tokenId)

4

User holds credits (same tokenId)

Token ID Lookup Patterns

Query Credits by Project

Query Project by Credit TokenId

Migration Considerations

From Option 1 to Option 2

1

Create Mapping Table

2

Migrate Existing Credits

  • Keep existing tokenIds

  • Add mapping entries

  • New batches use new tokenIds

3

Update Queries

  • Update balance queries to use mapping

  • Update project queries to aggregate batches

Best Practices

1

Consistent Naming

  • Use projectTokenId consistently

  • Clarify when tokenId refers to ProjectRecord vs Credit

2

Validation

  • Always validate ProjectRecord exists before configuring credits

  • Check tokenId ownership/validity

3

Documentation

  • Document tokenId strategy clearly

  • Provide examples for developers

4

Future-Proofing

  • Design contracts to support migration

  • Consider upgrade paths

Last updated