Basics
Native ITEMs are different from wrapped ITEMs in that they have all of the awesome ITEM standard implementations as well as the ability to maintain extended functionalities.
Native ITEMs in a collection inherit the functionalities from the collection extension. Using the extension, you can expand the scope of an ITEM to anything made possible by Solidity.
Read more about ITEMs Collection extensions here: Build Collections
The basic hosting functions of a single ITEM, even if inherited by the collection, can also be removed for Mint and Metadata updates.
Single ITEM Hosting: Mint and Metadata
1
//Let's create and unload the metadata on IPFS
2
var IPFSHttpClient = require('ipfs-http-client');
3
4
var ipfs = new IPFSHttpClient();
5
6
var metadata = {
7
licence_url : 'https://my.awesome_licence.com',
8
image : 'https://ipfs.io/ipfs/xxxx',
9
description : "My Item is the best on earth!"
10
}
11
12
var fileToUpload = [new Blob([JSON.stringify(metadata, null, 4)], { type: "application/json" })];
13
14
var metadataLink = "ipfs://ipfs/";
15
for await (var upload of ipfs.add(fileToUpload)) {
16
metadataLink += upload.path;
17
break;
18
}
19
20
//Now we can create a new objectId
21
var amountToMint = "100";
22
//Token name and symbol can be left blank. In that case, the collection ones will be used
23
var tokenName = "My awesome Item";
24
var tokenSymbol = "";
25
26
var objectUri = metadataLink;
27
28
//Editable true means that the host can mint more tokens later or change the uri.
29
var editable = true;
30
31
//Take the current block number, useful for search later
32
var blockNumber = web3.eth.getBlockNumber();
33
34
await collection.contract.methods.mint(amountToMint, tokenName, tokenSymbol, objectUri, editable).send();
35
36
//Unfortunately, actually it is not possible to grab return types of Smart Contract from web3, so we need to search for the NewToken event in the blockchain to retrieve the new item
37
var logs = await web3.eth.getPastLogs({
38
address : collection.addres,
39
topics : [web3.utils.sha3("NewItem(uint256,address)")],
40
fromBlock : blockNumber,
41
toBlock : 'latest'
42
});
43
44
var collectionItemObjectId = web3.eth.abi.decodeParameter("uint256", logs[0].topics[1]);
45
46
//We've chosen editable = true, this means that we can now mint more tokens for this objectId
47
48
//Let's mint 100 more tokens
49
await collection.contract.methods['mint(uint256,uint256)'](collectionItemObjectId, amountToMint).send();
50
51
//Let's change the URI
52
metadata.licence_url = "https://another.uri.licence.com";
53
54
fileToUpload = [new Blob([JSON.stringify(metadata, null, 4)], { type: "application/json" })];
55
56
metadataLink = "ipfs://ipfs/";
57
for await (var upload of ipfs.add(fileToUpload)) {
58
metadataLink += upload.path;
59
break;
60
}
61
62
await collection.contract.methods.setUri(collectionItemObjectId, metadataLink).send();
63
64
//And now let's make this item read only
65
await collection.contract.methods.makeReadOnly(collectionItemObjectId).send();
66
67
//From now on, for this single objectId, no more tokens can be minted and the token uri cannot be change anymore
Copied!
Copy link