5.4 KiB
description |
---|
Discover all about the extensible & flexible smart contract templates. |
Datatoken Templates
Each data NFT or datatoken within Ocean Protocol is generated from pre-defined template contracts. The templateId parameter specifies the template used for creating a data NFT or datatoken, which can be set during the creation process. The templateId is stored within the smart contract code and can be accessed using the getId() function.
it("#getId - should return templateId", async () => {
const templateId = 1;
assert((await erc20Token.getId()) == templateId);
});
Currently, Ocean Protocol supports 1 template type for data NFTs and 2 template variants for datatokens: the regular template and the enterprise template. While these templates share the same interfaces, they differ in their underlying implementation and may offer additional features.
The details regarding currently supported datatoken templates are as follows:
Regular template
The regular template allows users to buy/sell/hold datatokens. The datatokens can be minted by the address having a MINTER
role, making the supply of datatoken variable. This template is assigned templateId
``= 1
and the source code is available here.
Enterprise template
The enterprise template has additional functions apart from methods in the ERC20 interface. This additional feature allows access to the service by paying in the basetoken instead of the datatoken. Internally, the smart contract handles the conversion of basetoken to datatoken, initiating an order to access the service, and minting/burning the datatoken. The total supply of the datatoken effectively remains 0 in the case of the enterprise template. This template is assigned templateId =
2
and the source code is available here.
Set the template
When you're in the process of creating an NFT, it's essential to indicate the specific template it should utilize.
{% tabs %}
{% tab title="Ocean.js" %}
To personalize the template via ocean.js, you can achieve it by customizing the NFTCreateData with your desired templateIndex
.
The default template used is 1.
export interface NftCreateData {
name: string
symbol: string
templateIndex: number
tokenURI: string
transferable: boolean
owner: string
}
{% endtab %}
{% tab title="Ocean.py" %}
To personalize the template via ocean.py, you can achieve it by customizing the DataNFTArguments with your desired template_index
.
The default template used is 1.
name: str name of data NFT if creating a new one
symbol: str symbol of data NFT if creating a new one
template_index: int template index of the data NFT, by default is 1.
additional_datatoken_deployer: str address of an additional ERC20 deployer.
additional_metadata_updater: str address of an additional metadata updater.
uri: str URL of the data NFT.
"""
def __init__(
self,
name: str,
symbol: str,
template_index: Optional[int] = 1,
additional_datatoken_deployer: Optional[str] = None,
additional_metadata_updater: Optional[str] = None,
uri: Optional[str] = None,
transferable: Optional[bool] = None,
owner: Optional[str] = None,
)...
{% endtab %} {% endtabs %}
{% hint style="info" %} By default, all assets published through the Ocean Market use the Enterprise Template. {% endhint %}
Retrieve the template
To identify the template used for a specific asset, you can easily retrieve this information using the network explorer. Here are the steps to follow:
-
Visit the network explorer where the asset was published.
-
Search for the datatoken address 🔍
-
Once you have located the datatoken address, click on the contract tab to access more details.
-
Within the contract details, we can identify and determine the template used for the asset.
We like making things easy 😎 so here is an even easier way to retrieve the info for this asset published in the Ocean Market:
{% @arcade/embed flowId="wxBPSc42eSYUiawSY8rC" url="https://app.arcade.software/share/wxBPSc42eSYUiawSY8rC" %}
{% hint style="info" %} It's important to note that Ocean Protocol may introduce new templates to support additional variations of data NFTs and datatokens in the future. {% endhint %}