From 309c1c25f2634500fdfe7b41c5c31b716f977df7 Mon Sep 17 00:00:00 2001 From: Damjan Dimitrov Date: Fri, 12 Apr 2024 12:50:56 +0200 Subject: [PATCH] Add Substrate NFT support on CLI --- LICENSE | 2 +- packages/cli/README.md | 2 +- packages/cli/package.json | 2 +- packages/cli/src/modules/nfts/nft.service.ts | 9 ++++++--- packages/cli/src/modules/nfts/nfts.commands.ts | 6 ++++++ 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/LICENSE b/LICENSE index 8477a35..6fee85c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Apillon +Copyright (c) 2024 Apillon Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/packages/cli/README.md b/packages/cli/README.md index 05dfeb7..95d69b2 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -600,7 +600,7 @@ apillon nfts get-collection --uuid "123e4567-e89b-12d3-a456-426655440000" #### `nfts create-collection` -Creates a new NFT collection. The JSON file needs to have the property structure as type `ICreateCollection`, which can be found in the [SDK docs](https://sdk-docs.apillon.io/interfaces/ICreateCollection.html). An example object can be also seen on the [NFT SDK docs](https://wiki.apillon.io/build/5-apillon-sdk.html#nfts). +Creates a new NFT collection. The JSON file needs to have the property structure as type [ICreateCollection](https://sdk-docs.apillon.io/interfaces/ICreateCollection.html) for EVM and [ICreateSubstrateCollection](https://sdk-docs.apillon.io/interfaces/ICreateSubstrateCollection.html) for Substrate collections. An example object can be also seen on the [NFT SDK docs](https://wiki.apillon.io/build/5-apillon-sdk.html#nfts). **Options** diff --git a/packages/cli/package.json b/packages/cli/package.json index 2b739e2..eae0042 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,7 +1,7 @@ { "name": "@apillon/cli", "description": "▶◀ Apillon CLI tools ▶◀", - "version": "1.2.2", + "version": "1.3.0", "author": "Apillon", "license": "MIT", "main": "./dist/index.js", diff --git a/packages/cli/src/modules/nfts/nft.service.ts b/packages/cli/src/modules/nfts/nft.service.ts index 0f68b46..f27f966 100644 --- a/packages/cli/src/modules/nfts/nft.service.ts +++ b/packages/cli/src/modules/nfts/nft.service.ts @@ -1,4 +1,4 @@ -import { ICreateCollection, Nft, toInteger } from '@apillon/sdk'; +import { Nft, toInteger } from '@apillon/sdk'; import { readAndParseJson } from '../../lib/files'; import { GlobalOptions } from '../../lib/types'; import { paginate } from '../../lib/options'; @@ -30,7 +30,7 @@ export async function createCollection( await withErrorHandler(async () => { let createCollectionData; try { - createCollectionData = readAndParseJson(filePath) as ICreateCollection; + createCollectionData = readAndParseJson(filePath); } catch (e) { if (e.code === 'ENOENT') { return console.error(`Error: File not found (${filePath}).`); @@ -46,8 +46,11 @@ export async function createCollection( if (!createCollectionData) { return; } + const nft = new Nft(optsWithGlobals); + const data = optsWithGlobals.substrate + ? await nft.createSubstrate(createCollectionData) + : await nft.create(createCollectionData); - const data = await new Nft(optsWithGlobals).create(createCollectionData); console.log(data.serialize()); console.log('NFT collection created successfully!'); }); diff --git a/packages/cli/src/modules/nfts/nfts.commands.ts b/packages/cli/src/modules/nfts/nfts.commands.ts index 2be04b3..b57a8f2 100644 --- a/packages/cli/src/modules/nfts/nfts.commands.ts +++ b/packages/cli/src/modules/nfts/nfts.commands.ts @@ -57,6 +57,12 @@ export function createNftsCommands(cli: Command) { .command('create-collection') .description('Create NFT collection from JSON file') .argument('', 'path to JSON data file of type ICreateCollection') + .addOption( + new Option( + '--substrate', + 'Create the collection on substrate environment', + ), + ) .action(async function (filePath: string) { await createCollection(filePath, this.optsWithGlobals()); });