1const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api');2const config = require('./config');3const fs = require('fs');45function submitTransaction(sender, transaction) {6 return new Promise(async function(resolve, reject) {7 try {8 const unsub = await transaction9 .signAndSend(sender, (result) => {10 console.log(`Current tx status is ${result.status}`);1112 if (result.status.isInBlock) {13 console.log(`Transaction included at blockHash ${result.status.asInBlock}`);14 resolve();15 unsub();16 } else if (result.status.isFinalized) {17 console.log(`Transaction finalized at blockHash ${result.status.asFinalized}`);18 resolve();19 unsub();20 }21 });22 }23 catch (e) {24 reject(e.toString());25 }26 });27}2829async function createCollectionAsync(api, alice) {30 // Artwork31 const name = [65, 114, 116, 119, 111, 114, 107];32 // Collection of photos33 const description = [67, 111, 108, 108, 101, 99, 116, 105, 111, 110, 32, 111, 102, 32, 112, 104, 111, 116, 111, 115];34 // ART35 const tokenPrefix = [65, 82, 84];3637 // Mode: Re-Fungible38 const tx = api.tx.nft.createCollection(name, description, tokenPrefix, {"ReFungible": [config.collectionDataSize, config.decimalPoints]});39 await submitTransaction(alice, tx);4041 const tx2 = api.tx.nft.setOffchainSchema(2, "https://ipfs-gateway.usetech.com/ipfs/QmUSv64cUmL2m44QYkUFWmH89qykC8VLPFwjhpeAScjejS/image{id}.jpg");42 await submitTransaction(alice, tx2);43}4445async function main() {46 // Initialise the provider to connect to the node47 const wsProvider = new WsProvider(config.wsEndpoint);48 // Create the API and wait until ready49 const api = await ApiPromise.create({50 provider: wsProvider,51 });5253 // Owners's keypair54 const keyring = new Keyring({ type: 'sr25519' });55 const owner = keyring.addFromUri(config.ownerSeed);56 console.log("Collection owner address: ", owner.address);5758 // Create collection as owner59 console.log("=== Create collection ===");60 await createCollectionAsync(api, owner);6162}6364main().catch(console.error).finally(() => process.exit());