NFT
1. create an collection class
```javascript=
const api = ... // karura api
const call = api.tx.nft.createClass(
// file CID on ipfs
'bafybeicyv4abz4fjbirabb322bd5c6bcoitoqjrh4ea75psovp62lmy724',
// the properties of the class:
// Transferable: 0b00000001,
// Burnable: 0b00000010,
// Mintable: 0b00000100,
// ClassPropertiesMutable: 0b0001000
// 0b00001111 means that [Transferable, Burnable, Mintable, Mutable]
0b00001111,
// attributes for the collections
api.createType("Attributes", {})
)
await call.signAndSend(...)
```
2. mint NFT
**Mint NFT will reserved some tokens, pls. ensure the owner has enough token.
The owner address is not the creator address, it can be get from `api.query.ormlNFT.classes`**
```javascript=
const api = ... // karura api
const classId = ... // the classId of NFT
const to = ... // to address
const quantity = 1 // mint quantity
const managerAccount = ... // the class creator
// query the classInfo first
const classInfo = await api.query.ormlNFT.classes(classId);
// get the class owner account
const owner = classInfo.unwrapOrDefault().owner.toString();
const call = api.tx.proxy.proxy(owner, 'Any', api.tx.nft.mint(
// to address
to,
// class id
classId,
// special CID for the NFT
'',
// special attributes for the NFT
api.createType('Attributes', {}),
// mint quantity
quantity
))
await call.signAndSend(managerAccount);
```
3. transfer NFT
```javascript=
const api = ... // karura api
const classId = ... // the classId of NFT
const toAddress = ...
const tokenId = ...
const nftOwnerAccount = ... // the owner of the nft
const call = api.tx.nft.transfer(to, [classId, tokenId]);
await call.signAndSend(nftOwnerAccount)
```
4. query all NFTs in `classId` belong to `account`
```javascript=
const api = ...
const classId = ... // the classId of NFT
const account = ...
const tokens = await api.query.ormlNFT.tokensByOwner.entries(account, classId);
const tokenIds = tokens.map(([key, value]) => {
const tokenId = key.args[2].toString();
return tokenId
})
```
5. update the `classId` properties
```javascript=
const api = ... // karura api
const classId = ... // the classId of NFT
const managerAccount = ... // the class creator
// query the classInfo first
const classInfo = await api.query.ormlNFT.classes(classId);
// get the class owner account
const owner = classInfo.unwrapOrDefault().owner.toString();
const call = api.tx.proxy.proxy(
owner,
'Any',
api.tx.nft.updateClassProperties(
classId,
// new properties
0b00001111
)
)
await call.signAndSend(managerAccount)
```