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}`);11 12 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];36 37 // 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 const rtt = JSON.parse(fs.readFileSync("runtime_types.json"));4950 // Create the API and wait until ready51 const api = await ApiPromise.create({ 52 provider: wsProvider,53 types: rtt54 });5556 // Owners's keypair57 const keyring = new Keyring({ type: 'sr25519' });58 const owner = keyring.addFromUri(config.ownerSeed);59 console.log("Collection owner address: ", owner.address); 6061 // Create collection as owner62 console.log("=== Create collection ===");63 await createCollectionAsync(api, owner);6465}6667main().catch(console.error).finally(() => process.exit());