Craftable Input Token

A description of the Abstract Contract for Input Tokens

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 definition metadata 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 CraftableBase. 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


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.

Last updated