Skip to main content

Create Private NFT

In this tutorial you will learn how to integrate your dApp with Arcana Storage SDK and allow dApp users to create a private NFT.

tip

Alternatively, to mint private NFTs, dApp users can also use Arcana NFT Minter dApp:

https://nft-minter.beta.arcana.network/

After minting private NFTs using Arcana NFT Minter, private NFT owners can view them using the Arcana NFT Viewer dApp:

https://nft-viewer.dev.arcana.network/

Prerequisites

  • Use Arcana Developer Dashboard to register and configure your dApp.
  • Integrate your dApp with MetaMask in order to obtain Ethereum provider. This is required to get a signer for minting the NFT on a blockchain of your choice.
note

Arcana NFT Minter dApp supports MetaMask Wallet in the beta release. Other wallets including Arcana wallet will be supported in a future release.

Steps

Before we get into the details, here is some high level context.

  • Creating a private NFT requires you to first upload the NFT data or file to Arcana Store. This ensures your data is encrypted and access controlled. After a successful upload, you will receive a unique identifier for this file asset, the DID.

  • Next, you need to mint your NFT using the standard NFT minting process with some additional metadata. This involves two parts:

    • First, use the uploaded file DID, along with other details such as title, preview image to invoke makeMetadataURL function of the Arcana Storage SDK. This will return a metadata URL.
    • Use this metadata URL and wallet address obtained from the provider to mint NFT. You can use any supported blockchain network for minting. After minting, you will receive a tokenID for the freshly minted NFT.
note

Only the preview image is minted and made accessible publicly via the standard minting process. Your private NFT is secure in Arcana Store. The additional data used to mint NFT is utilized for ascertaining ownership and maintaining a one-to-one correspondence between the minted NFT and the actual private NFT data file secured in Arcana Store.

  • Finally, you need to link this tokenID obtained after minting with the DID of the private NFT on Arcana blockchain. After linking, the NFT creation process is complete.

Anyone can view the minted NFT preview image but only the owner or those who have been explicitly allowed access by the file owner can download the actual private NFT from Arcana Store.

With that high level context, dApp developers can use the steps listed below to create private NFT using Arcana Storage SDK:

Step 1: Integrate your dApp with Arcana Storage SDK

Ensure that you have addressed the prerequisite steps including MetaMask integration in your dApp. Then integrate your dApp with Arcana Storage SDK.

Step 2: Choose Arcana Network

Make sure you inform and prompt your dApp user to select "Arcana Network" in their MetaMask wallet settings. This is required to successfully execute the next step.

caution

For uploading the private NFT asset file to Arcana Store, you must ensure that the network selected in MetaMask wallet is set to "Arcana Network". Make sure the following details are specified correctly in the wallet network settings:

Field DescriptionValue
Network NameArcana Network
New RPC URL

https://blockchain001-testnet.arcana.network

ChainID

40405

Currency SymbolXAR
Block Explorer URL Optional

https://explorer.beta.arcana.network

note

The dApp developer can choose to take user's consent and automate the network switching process programmatically in the MetaMask wallet settings.

Use the MetaMask wallet configuration settings details to create Arcana Network in the MetaMask wallet. In your dApp, specify the designated values for chain ID, RPC URL, Network name field. Once user confirms the switching action in the dApp UI, switch to Arcana Network settings via dApp.

Step 3: Upload the NFT asset to Arcana Store

Assuming you have already integrated your dApp with Arcana Storage SDK, you can invoke the file uploader function to upload the NFT asset data file to the Arcana Store. Save the DID returned by this function. This is the unique ID assigned to your data file in Arcana Store.


// After integrating with Storage SDK initialize a Storage provider
storage = new StorageProvider({
appId: APP_ID,
gateway: GATEWAY_URL,
chainId: Number(BLOCKCHAIN_ID),
provider: window.ethereum,
})
// Use this Storage provider to upload your file

const uploader = await storage.getUploader()
//save DID
const did = await uploader.upload(file)

Step 4: Obtain makeMetaDataURL from Storage SDK

Use the following parameters to obtain metadata URL by invoking makeMetaDataURL function in the Storage SDK.

  • Title: Private NFT Asset title
  • Description: Brief information about the NFT Asset
  • DID: The unique file identifier returned after uploading the file to the Arcana Store
  • Preview Image: A low resolution preview image to recognize an NFT asset or its key characteristics without sharing the actual NFT asset details.
  //save metadataURL
const metadataURL = await storage.makeMetadataURL(title, description, did, preview)

Step 5: Change the Network in MetaMask wallet

This is important. Before you mint this NFT using standard Ethereum minting process, make sure you inform and prompt the dApp user to change the network in their MetaMask wallet to the blockchain where you would like to mint this NFT. It will require non-zero eth in your wallet. Choose from one of the supported blockchains for minting:

  • Ropsten (Ethereum Testnet)
  • Mumbai (Polygon Testnet)

caution

Before minting, you must change the network to one of the supported blockchain networks:

  • Ropsten (Ethereum Testnet)
  • Mumbai (Polygon Testnet)

After minting, before linking the minted NFT token with DID, you need to change the MetaMask network setting back to "Arcana Network".

caution

When you change the network in MetaMask, the dApp browser page may reload. This will remove all stored values in current context. To make sure all the context is saved across page reload, make sure you save the DID, metadata URL and other details obtained in previous steps in local storage. This is MetaMask wallet specific behavior.

note

As mentioned earlier, the dApp developer can choose to programmatically switch MetaMask wallet to the user selected minting network. This network change must be done only after user confirms the action.

Step 6: Mint the NFT

To mint the NFT using the preview image and other requisite metadata, you need a blockchain signer. Use the code listed below to derive the ethereum provider from MetaMask and then obtain a blockchain signer using ethers.js library as shown in the code below:


//abi
const abi = [
{
inputs: [
{
internalType: 'address',
name: 'to',
type: 'address',
},
{
internalType: 'string',
name: 'tokenURI',
type: 'string',
},
],
name: 'mint',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'nonpayable',
type: 'function',
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'from',
type: 'address',
},
{
indexed: true,
internalType: 'address',
name: 'to',
type: 'address',
},
{
indexed: true,
internalType: 'uint256',
name: 'tokenId',
type: 'uint256',
},
],
name: 'Transfer',
type: 'event',
},
]

// mint NFT using ethers.js
const provider = window.ethereum
const web3Provider = new ethers.providers.Web3Provider(provider)
const signer = web3Provider.getSigner()
const NFT721Contract = new ethers.Contract(NFT_CONTRACT_ADDRESS, abi, signer)

In addition to the blockchain signer, you need the smart contract address and abi to mint the NFT. You can use the Arcana Smart Contract deployment address and its abi as listed below:

tip

Alternately, you can choose to not use Arcana Smart Contract and create your own collection / specify your own contract for minting the NFT. This process is more involved and you will be required to ensure that your contract notifies the Arcana Bridge adequately for any ownership changes on this NFT to register properly in the Arcana Store. Refer to the detailed instructions here.

Invoke the mint function and specify the wallet address and metadata URL obtained in an earlier step, during minting.

  let tx = await NFT721Contract.mint(walletAddress, metadataURL)
tx = await tx.wait()

On success, the mint function returns an array of events. Grab the Transfer event and obtain the corresponding tokenID using the code below:

  const event = tx.events.find((item) => item.event === 'Transfer')
// save tokenId
const tokenID = event.args.tokenId.toString()

Step 7: Change the Network in MetaMask, again!

This is important. Before you link the tokenID received after minting with Arcana Store DID, you need to change the network in MetaMask wallet to "Arcana Network".

note

This network change in MetaMask wallet can either be performed by the user manually or the dApp can do this switching programmatically, once the user approves the switching action.

Use the tokenID obtained after minting step, DID obtained after the NFT file upload step, the chainID corresponding to the selected blockchain where you minted the NFT and the NFT smart contract address (Arcana Smart Contract or the one you deployed) and invoke the Arcana Storage SDK function linkNFT as shown below:

  // Link NFT tokenID to Arcana Store DID
await storage.linkNft(did, tokenId, nftContractAddress, chainId)

Step 9: Verify private NFT creation

Verify that your private NFT is created by using Arcana NFT Viewer. If you specify the DID and use the same MetaMask wallet account that was used to mint this NFT, you will be able to download this private NFT. Otherwise, if you specify the DID but use a different MetaMask account that did not create this NFT and does not own it, you can simply see a preview of the NFT asset but cannot download it.

That is all! 🎉

You have successfully created a private NFT using Arcana Storage SDK!

What's Next?

See also