ERC-1155 的輸入規格檔案

區塊鏈 App 產生器初始化命令會讀取輸入規格檔案,並使用數個工具產生鷹架式專案,以協助鏈碼開發處理作業。

您可以定義標準資產,以及根據相同規格檔案中 ERC-1155 標準的有趣與不可行的變數替代字資產。您無法根據相同規格檔案中的一個以上的標準來定義變數替代字資產。

如需在規格檔案中包含標準資產的資訊,請參閱輸入規格檔案

Blockchain App Builder 套件提供下列 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:此行為支援停用或燒錄記號。燒錄並不會刪除記號,而是會讓記號處於無法使用的永久狀態。燒錄無法回復 。
  • 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