ERGO
Token Mechanics
Beginner
30 minutes

Ergo 上的同质化代币铸造(EIP‑4)

使用 EIP‑4 标准,在一笔交易中创建标准同质化代币

GitHub

问题

你需要为 dApp、社区或项目创建代币,但不想维护复杂的基础设施。

解决方案

Ergo 的 EIP‑4 标准允许在单笔交易中铸造代币。第一个输出 box 使用第一个输入 box 的 ID 作为代币 ID,确保全局唯一。

工作原理

  1. 1Create a transaction with at least one input box
  2. 2The first output box declares the new token with amount and metadata
  3. 3Token ID is automatically derived from INPUTS(0).id
  4. 4Registers R4-R6 store name, description, and decimals per EIP-4
  5. 5R7-R9 available for custom application data
  6. 6Transaction is signed and broadcast to the network

代码示例

{
  // Token minting happens automatically when:
  // 1. This is the first output box (index 0)
  // 2. Token amount is specified in the box
  // 3. Token ID = INPUTS(0).id (derived automatically)
  
  // EIP-4 Register Layout:
  // R4: Token name (Coll[Byte] - UTF-8)
  // R5: Token description (Coll[Byte] - UTF-8)
  // R6: Number of decimals (Int)
  // R7-R9: Application-specific data
  
  // Simple guard: only creator can mint
  val creatorPK = PK("9f...")
  proveDlog(creatorPK)
}

The simplest token minting pattern. Token ID is deterministically derived from the first input, ensuring uniqueness. EIP-4 defines the standard register layout for interoperability.

使用场景

  • Governance tokens for DAOs
  • Loyalty points and rewards
  • Stablecoins with collateral backing
  • Community and meme tokens
  • Utility tokens for dApps

安全注意事项

  • !Token ID is immutable once created
  • !Metadata in registers cannot be changed after minting
  • !Consider using a dedicated minting contract for controlled issuance
  • !Verify token amounts before signing

实际项目应用

SigmaUSD

Algorithmic stablecoin using minting pattern

Ergo Raffle

Raffle tickets as tokens

参考资源

手续费说明

Standard transaction fee (~0.001 ERG). No additional minting fees on Ergo.

提升你的 ErgoScript 技能

获取新模式、教程和开发者资源的最新通知。

Follow for daily updates