ERC-1155 的输入规范文件

Blockchain App Builder 初始化命令读取输入规范文件,并使用多个工具生成基架项目,以协助链码开发过程。

您可以在同一规范文件中定义基于 ERC-1155 标准的标准资产以及可替换和非可替换标记资产。不能根据同一规范文件中的多个标准定义标记资产。

有关在规范文件中包括标准资产的信息,请参见 Input Specification File

区块链应用程序构建器包中提供了以下 ERC-1155 令牌资产的示例规范文件:
  • NFTArtCollectionMarketplacewithERC1155-TypeScript.yml
  • FractionalNFTinRealEstate-TypeScript.yml

除了标准属性和节外,令牌资产还支持规范文件中的 behavioranatomy 部分。此外,不可替换的令牌资产支持 metadata 部分。以下示例显示了两个 ERC-1155 令牌资产的规范文件的结构,一个完整的不可替换令牌和一个小数可替换令牌:

assets:
    - name: ArtCollection #Asset name
      type: token #Asset type
      standard: erc1155+   # Token standard
      
      anatomy:
          type: nonfungible # Token type
          unit: whole  #Token unit
      
      behavior:
        - indivisible                
        - mintable:                   
            max_mint_quantity: 20000
        - transferable                
        - burnable
        - lockable
        - roles:
            minter_role_name: minter
      
      properties:  # Custom asset attributes for non-fungible token 
          
          - name: price # Custom asset attribute to set the price of a non-fungible token in the marketplace
            type: number
          
          - name: on_sale_flag # Custom asset attribute maintains non-fungible token selling status in the marketplace
            type: boolean
      
      metadata: #  Use this section to maintain the metadata on the blockchain. Only the user creating the non-fungible token can assign metadata attribute values, which cannot be updated later.
          
          - name: painting_name
            type: string
          
          - name: description
            type: string
          
          - name: image
            type: string
          
          - name: painter_name
            type: string

    - name: Loyalty # Asset name
      type: token  # Asset type
      standard: erc1155+   # Token standard

      anatomy: 
          type: fungible # Token type
          unit: fractional # Token unit

      behavior: # Token behaviors
          - divisible: 
                decimal: 2  
          - mintable: 
                max_mint_quantity: 10000 
          - transferable
          - burnable 
          - roles: 
                minter_role_name: minter 

      properties:
          - name: currency_name # Custom attribute to represent the token in a specific currency.
            type: string

          - name: token_to_currency_ratio # Custom attribute to specify the token to currency ratio.
            type: number

以下示例显示了小数不可替换标记的规范文件的结构:

- name: RealEstateProperty #Asset name
      type: token #Asset type
      standard: erc1155+ # Token standard
      
      anatomy:
          type: nonfungible # Token type
          unit: fractional #Token unit
      
      behavior:
        - divisible:
        - mintable:
        - transferable
        - roles:
            minter_role_name: minter
      
      properties: # Custom asset attributes for non-fungible token.
          
          - name: propertySellingPrice # Custom asset attribute to set the real estate property selling price
            type: number
 
          - name: propertyRentingPrice # Custom asset attribute maintains the renting amount for the real estate property
            type: number
            
      metadata: # To maintain the metadata on-chain, this tag will be used. Users won't be able to update the metadata attribute values.
          
          - name: propertyType
            type: string
 
          - name: propertyName
            type: string
 
          - name: propertyAddress
            type: string
          
          - name: propertyImage
            type: string

表 7-7 ERC-1155 标记规范文件的参数说明和示例

进入 说明 示例
type:

必须在 assets 部分中指定 type: token

assets:
    - name: ArtCollection #Asset name
      type: token #Asset type
standard: 对于 ERC-1155 令牌,standard 属性是必需的。它表示链代码生成期间要遵循的标记标准。
standard: erc1155+ # Token standard
anatomy:
anatomy 部分有两个必需的参数:
  • type: nonfungibletype: fungible

    不可替代的令牌是唯一的。

  • unit: wholeunit: fractional

    整个令牌不能细分为较小的分数单位。小数标记可以根据指定的小数位数细分为较小的单位或份额。

anatomy:
          type: nonfungible # Token type
          unit: whole #Token unit
behavior: 本节介绍令牌的功能和限制。mintabletransferable 行为对于所有令牌都是必需的。indivisible 行为对于整个不可替代的令牌是必需的。
  • indivisible:此行为支持限制,因此不能将整个令牌细分为分数。
  • divisible:此行为描述如何细分标记。decimal 参数指定可使用的小数位数。使用小数位数可能的最小分数是可拥有的标记的最小单位。如果未指定 decimal 参数,则缺省值为零个小数位。
  • mintable:此强制行为支持铸造新的令牌实例。可选的 max_mint_quantity 参数指定可以铸造的标记的总数。如果未指定 max_mint_quantity 参数,则可以铸造任意数量的标记。
  • transferable:此强制行为支持转移令牌的所有权。
  • burnable:此行为支持停用或刻录令牌。Burning 不会删除令牌,而是将其置于无法使用的永久状态。燃烧是不可逆转的。
  • lockable:此行为是可选的,仅由不可替代的令牌支持。此行为允许令牌所有者锁定不可替换的令牌。锁定的令牌无法传输到其他任何用户或由其他用户刻录。
  • roles:此行为将令牌行为限制为具有特定角色的用户。当前有两个角色可用:minter_role_nameburner_role_name。如果不指定角色,则任何用户都可以充当矿工或燃烧器。例如,如果未指定刻录者角色,则任何帐户用户隐式都具有刻录者角色。如果指定了刻录器角色,则在标记设置过程中,Token Admin 用户必须将刻录器角色显式分配给其他用户。
behavior:
        - indivisible
        - mintable:
            max_mint_quantity: 20000
        - transferable
        - burnable
        - lockable
        - roles:
            minter_role_name: minter
metadata:

metadata 属性是可选的,仅由不可替代的标记支持。此属性为不可替代的令牌指定存储在区块链上的元数据信息。元数据属性值只能由创建标记的标记所有者分配,并且不能在创建标记后进行更新。

在示例中,name 是元数据属性的名称,type 是属性具有的值类型。

metadata:
                                
                                - name: painting_name
                                type: string
                                
                                - name: description
                                type: string
                                
                                - name: image
                                type: string
                                
                                - name: painter_name
                                type: string

限制

Blockchain App Builder 为 ERC-1155 标准提供了部分支持。当前,不支持以下 ERC-1155 事件和方法。

事件:
  • TransferSingle
  • TransferBatch
  • ApprovalForAll
  • URI
方法:
  • safeTransferFrom
  • balanceOf
  • setApprovalForAll
  • isApprovedForAll