Last active
December 2, 2022 12:02
-
-
Save fend25/32cb63df03a7c0f720dc2d1b161b6a70 to your computer and use it in GitHub Desktop.
Brief Unique collection and token creation overview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Sdk} from "@unique-nft/sdk"; | |
import {KeyringProvider} from "@unique-nft/accounts/keyring"; | |
import { | |
AttributeType, | |
COLLECTION_SCHEMA_NAME, | |
UniqueCollectionSchemaToCreate, | |
UniqueTokenToCreate | |
} from '@unique-nft/schemas' | |
/* | |
// For browser extension: | |
import {Polkadot} from "@unique-nft/utils/extension"; | |
const result = await Polkadot.enableAndLoadAllWallets(); | |
const sdk = new Sdk({baseUrl: 'https://rest.unique.network/opal/v1', signer: result.accounts[0].uniqueSdkSinger}) | |
*/ | |
const account = await KeyringProvider.fromMnemonic('coral parent ...') | |
console.log(account.getAddress()) | |
const sdk = new Sdk({ | |
baseUrl: 'https://rest.unique.network/opal/v1', | |
signer: account, | |
}) | |
const balance = await sdk.balance.get({address: account.getAddress()}) | |
console.log(balance) | |
console.log("PLEASE REMOVE process.exit at the Line 30");process.exit() | |
const collection: UniqueCollectionSchemaToCreate = { | |
schemaName: COLLECTION_SCHEMA_NAME.unique, | |
schemaVersion: '1.0.0', | |
image: { | |
urlTemplate: 'https://gateway.pinata.cloud/ipfs/{infix}' | |
}, | |
video: { | |
urlTemplate: 'https://gateway.pinata.cloud/ipfs/{infix}' | |
}, | |
coverPicture: { | |
ipfsCid: 'QmNiBHiAhsjBXj5cXShDUc5q1dX23CJYrqGGPBNjQCCSXQ' | |
}, | |
attributesSchemaVersion: '1.0.0', | |
attributesSchema: { | |
0: { | |
name: {_: 'attr numero uno'}, | |
type: AttributeType.string, | |
optional: true, | |
isArray: false, | |
}, | |
1: { | |
name: {_: 'attr numero dos'}, | |
type: AttributeType.string, | |
optional: false, | |
isArray: false, | |
enumValues: { | |
0: {_: 'value 1'}, | |
1: {_: 'value 2'}, | |
} | |
}, | |
2: { | |
name: {_: 'attr numero tres'}, | |
type: AttributeType.string, | |
optional: true, | |
isArray: true, | |
enumValues: { | |
0: {_: 'value 1'}, | |
1: {_: 'value 2'}, | |
2: {_: 'value 3'}, | |
} | |
} | |
}, | |
} | |
const collectionResult = await sdk.collections.creation.submitWaitResult({ | |
address: account.getAddress(), | |
name: 'test', | |
description: 'test', | |
tokenPrefix: 'TEST', | |
schema: collection, | |
tokenPropertyPermissions: [ | |
{ | |
key: 'a.0', | |
permission: { | |
mutable: true, | |
tokenOwner: true, | |
collectionAdmin: true, | |
} | |
} | |
] | |
}) | |
console.log(collectionResult.parsed) | |
const token: UniqueTokenToCreate = { | |
name: {_: 'my token'}, | |
description: {_: 'my token'}, | |
image: { | |
ipfsCid: 'QmNiBHiAhsjBXj5cXShDUc5q1dX23CJYrqGGPBNjQCCSXQ', | |
}, | |
video: { | |
urlInfix: '/1.mp4', | |
}, | |
encodedAttributes: { | |
0: {_: 'value uno'}, | |
1: 0, | |
2: [0, 2], | |
} | |
} | |
const tokenResult = await sdk.tokens.create.submitWaitResult({ | |
address: account.getAddress(), | |
collectionId: collectionResult.parsed!.collectionId, | |
data: { | |
...token as any | |
} | |
}) | |
console.log(tokenResult.parsed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment