Craftable Output Token

A token can be both a Craftable input and output

What's CraftableIn?

It's an abstract contract providing all necessary functionality to be adapted as an output in future crafting rules. This involves reading and writing attributes and template, as well as minting tokens from the crafting rule.

Implementing CraftableOut in your Token

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

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

  2. import craftable/CraftableOut.sol from the repo.

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

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

First override the functions to enable CraftableBase. Other functions to override for CraftableOut specifically are the following:

  • _storeTemplateData( _id, _template, _class, _attributes) This function is given an _attributes list and the purpose of this function is to handle the storage of the attributes to a specific template id and class id. this is important to allow the flexibility of the developer.

  • _templateURI( _template ) Given the tokens with the same template have the same values for the attributes, the URI for the token metadata is the same as its template.

In addition to overriding some functions, we also provide private functions to provide minter approval. for example _setMintingRule(...) allows you to create public functions that have some logic before adding random users.

Docs

Functions

templateIfExists( _class, _attributes )

template( _class, _attributes )

_setMintingRule( addr, _canMint ) [internal]

canMint( ruleAddress)

mint( user, template, amount, craftingHash )

burn( id, amount )

tokenURI( id )

templateIfExists( uint256 _class, uint256[] _attributes )

Since a template is identified by the _class of the item and _attributes values, this function checks if such a template exists and returns the template id as uint256. If the template does not exist, it returns 0.

template( uint256 _class, uint256[] _attributes )

Returns the template id that has this _class and _attributes. If the template does not exist, it creates a new one and returns the id.

_setMintingRule( address addr, bool _canMint )

Sets whether a rule at addr can mint or not.

canMint( address ruleAddress )

Checks if the crafting rule deployed at ruleAddress can take this token as output. it checks contracts that have been added through _setMintingRule(...).

mint( address user, uint256 template, uint256 amount, bytes32 craftingHash )

A function that mints tokens that can be only issued by approved crafting rules (the rules must evaluate canMint( ... ) to true). The craftingHash is supplied by the crafting rule to track the origins of the minted tokens.

burn ( uint256 id, uint256 amount )

A function that burns tokens that can be only issued by approved crafting rules (the rules must evaluate canMint( ... ) to true).

tokenURI ( uint256 id )

Returns the OpenSea Metadata URI for the token at id with the attribute values.

Last updated