Craftware Docs
  • What is Craftware?
    • Game Samples using Craftware
  • ❗Getting Started
  • SDKs
    • Unity3D SDK Guide
    • Golang SDK Guide
  • Blockchain Elements
    • Smart Contracts
    • ICraftableIn Library
  • 🎮Game Content
    • Game Assets
      • Resources
        • Create a resource
        • Retrieve Resources in Game
      • Currencies
      • Items
      • Properties
      • Export Assets Data
      • Import Assets Data
    • Crafting
      • Crafting Rule
  • 🤝Onchain Interoperability
    • Authentication
      • Wallet Binding
      • Wallet Session Authentication
      • Setting Up Wallet Authentication
    • Ports Protocol
      • Export Protocol
      • Import Protocol
    • Backward Compatibility
    • Crafting Protocol
      • Craftable Token
        • Definition Metadata
        • Craftable Input Token
        • Craftable Output Token
      • Crafting Rule Contract
        • Definition Metadata
      • Crafting Rule No-code Designer
  • ⚙️Admin
    • Account Settings
      • Account
      • Users
      • API Keys
      • Plan
      • Config
    • Security
    • Terms of Service
    • Privacy Policy
Powered by GitBook
On this page
  • What's CraftableIn?
  • Implementing CraftableIn in your Token
  • Docs

Was this helpful?

  1. Onchain Interoperability
  2. Crafting Protocol
  3. Craftable Token

Craftable Input Token

A description of the Abstract Contract for Input Tokens

PreviousDefinition MetadataNextCraftable Output Token

Last updated 1 year ago

Was this helpful?

A key constraint for the input tokens is that they must implement on-chain attribute storage.

What's CraftableIn?

It's an abstract contract providing all necessary functionality to be adapted as an input in future crafting rules.

Implementing CraftableIn in your Token

To turn your token in development into a Craftable Input token. Here are the instructions:

  1. Compose your file. Set the classes you have and their attributes descriptions.

  2. make sure to edit your contract to handle storing your token attribute on-chain.

  3. import craftable/CraftableIn.sol from the repo.

import "<codebase>/craftable/CraftableIn.sol";
  1. extend the abstract contract from your token

contract MyToken is ..., CraftableIn {
    ...
}
  1. Implement the virtual functions to make the contract usable.

First override the functions to enable Other functions to override for CraftableIn specifically are the following:

  • attributes( _id) This function returns a list of integers representing the attributes of the token ordered according to the definition. The implementation of this functions depends on how the original attributes were stored for the contract. We provide a simple example here:

contract Clothes is ERC1155, CraftableIn {
    
    //----- already existing
    struct MyAttrs{
        uint256 material;
        uint256 size;
    }
    
    mapping(uint256 => MyAttrs) public myTokenAttrs;
    //-----
    
// assuming order is [material, size, ...]
+  function attributes(
+    uint256 _id
+  ) public view override returns (uint256[] memory) {
     ... // checks
+    MyAttrs memory attr = myTokenAttrs[_id];
+    uint256[] memory _attr = new uint256[](2);     // create the output list
+    _attr[0] = attr.material;              // add values in the correct order.
+    _attr[1] = attr.size;
+    return _attr;
+  }    

}
  • (optional) tokenURI(_tokenId): This can be edited to use different contract scheme

Docs

Functions
attributes( uint256 _id )

Returns the list of attributes for the token at id _id. The order of the attributes must match the description for craftware.

🤝
attributes( _id )
definition metadata
CraftableBase.