GhostMarket
Search…
Phantasma NFT Creation
A developers guide to creating Phantasma NFTs compatible with GhostMarket

Introduction

This page provides step-by-step instructions for deploying GhostMarket compatible NFTs on the Phantasma blockchain.
The NFT creation process requires interaction with the blockchain. For retrieving existing NFT metadata, see Accessing NFT data, which uses the GhostMarket APIs.
The code snippets also assume a node.js environment.
See our Metadata Reference for full details and requirements of GhostMarket NFT metadata.

NFT Creation

The NFT creation process on all blockchains broadly consists of the following steps.
  1. 1.
    Prepare Off-Chain Metadata and persist it.
  2. 2.
    Assemble On-Chain Metadata and build a transaction.
  3. 3.
    Sign the transaction.
  4. 4.
    Broadcast to the blockchain.

1. Prepare Off-Chain Metadata

The preferred decentralised platform for persisting image/media data for your NFT is IPFS.
This guide will use PinΓ£ta to upload and pin your images to IPFS.
Set up a Pinata account and get started here.
You can either manually upload you metadata, noting the IPFS hash, or dive into the Pinata js-sdk to interract with Pinata programatically.
Note the IPFS hash of the uploaded metadata, you will need it in the next step.

2. Assemble On-Chain Metadata

Ghostmarket Phantasma NFT contract stores all metadata on-chain, so you must assemble it into a Phantasma transaction script.
We will use the phantasma-ts npm module to work with the Phantasma blockchain.

Install the module

% npm install phantasma-ts

Import the library

const { phantasmaJS } = require("phantasma-ts");
The Minting Data is sent to the contract as an array. The following table specifies the contents of the array.
All elements must be provided.

Phantasma "ghost" mint contract parameters

index
name
type
descr
0
editionId
number
0 for new series // != 0 for existing series
1
editionMax
number
Maximum number possible
2
editionMode
number
1 = duplicated, 2 = unique // only allow duplicate for now
3
creator
address
Address of the creator
4
royalties
number
Royalties in BPS (0.01%) - must be integer
5
mintTicker
string
​
6
numOfNfts
number
number to mint
7
name
string
Short name of the NFT
8
description
string
long descriptive name of the NFT
9
type
number/integer
Genre of the NFT - see Genre reference
10
imageURL
string
URL of the image - ipfs://<hash>
11
infoURL
string
Currently unused
12
attrT1
string
First attribute Type/Key, e.g. "Color"
13
attrV1
string
First attribute Value, e.g. "Red"
14
attrT2
string
Second attribute Type/Key
15
attrV2
string
Second attribute Value
16
attrT3
string
Third attribute Type/Key
17
attrV3
string
Third attribute Value
18
lockedContent
string
String containing the encrypted content
19
listPrice
number
If listing with Mint, the listing price
​

Assemble the Minting Parameter Array

let creatorAdd = "<my Phantasma address>";
​
mintParamArrayGhost = [
0, // editionID
100, // editionMax
1, // editionMode
creatorAdd, // creator - address
2000, // royalties - 20% expressed as BPS (0.01%)
"GHOST", // mintTicker - string
1, // numOfNfts - Mint one NFT
"My Shiny NFT", // name
"This NFT will be a classic", // description
1, // type - See Metadata Reference "Genre"
"ipfs://QmTy8w65yBXgyfG2ZBg5TrfB2hPjrDQH3RCQFJGkARStJb", // imageURL - from step 1
"", // infoURL - not used
"color", // attrT1
"red", // attrV1
"size", // attrT2
"small", // attrV2
"", // attrT3 - empty string if unused
"", // attrV3 - empty string if unused
"This is your mystery content", // lockedContent
0, // listPrice - we can list later, not now
"", // listPriceCurrency - not listing with mint
0, // listLastEndDate - not listing
"", // infusedAsset - string
0, // infusedAmount - number
true, // hasLocked - true
];

3. Build the transaction script

//Create a new Script Builder Object
let sb = new phantasmaJS.ScriptBuilder();
​
// Assemble the Script
sb.callContract("gas", "AllowGas", [
"fromAddress",
sb.nullAddress,
"100000",
"900",
])
.callContract("ghost", "mintToken", mintParamArrayGhost)
.callContract("gas", "SpendGas", ["fromAddress"])
.endScript();

3. Construct & Sign the transaction

// stringify the script
let script = sb.str;
let privateKey = "Your Private Key";
​
//build an expiration date for the transaction of 5 minutes
let expiration = 5; //Expiration time, in minutes
let getTime = new Date();
let expDate = new Date(getTime() + expiration * 60000);
​
//Creating New Transaction Object
let transaction = new phantasmaJS.Transaction(
"mainnet", //Nexus Name
"main", //Chain
script, //In string format
date, //Expiration Date
""
); //Extra Info to attach to Transaction in Serialized Hex - not needed
​
//Sign's Transaction with Private Key
await transaction.sign(privateKey);

4. Broadcast to the blockchain

Finally, broadcast the transaction
//Send Transaction
let txHash = await RPC.sendRawTransaction(transaction.toString(true));
Congratulations! you have successfully deployed a GhostMarket compatible NFT to the "ghost" contract on the Phantasma blockchain.
For clarity, all of the above snippets exclude error and promise handling for clarity. Production code should include thorough exception management and handle promises appropriately.