Skip to content

Commit

Permalink
Add Substrate NFT support on CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitrov-d committed Apr 12, 2024
1 parent 9669584 commit 309c1c2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 6 additions & 3 deletions packages/cli/src/modules/nfts/nft.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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}).`);
Expand All @@ -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!');
});
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/modules/nfts/nfts.commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export function createNftsCommands(cli: Command) {
.command('create-collection')
.description('Create NFT collection from JSON file')
.argument('<file-path>', '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());
});
Expand Down

0 comments on commit 309c1c2

Please sign in to comment.