# NFTs on Solana

<details>

<summary><mark style="color:purple;">Straight to the code!</mark></summary>

Instantiate Cryptum SDK first:

```javascript
const sdk = new CryptumSdk({
  environment: 'testnet',
  apiKey: 'YOUR-API-KEY',
})
```

### Create NFTs

Create an NFT in Solana.

**`sdk.nft.create(opts)`**

* `opts.protocol` (string)(**required**) - blockchain protocol must be `SOLANA`.
* `opts.wallet` (Wallet)(**required**) - wallet to sign the transaction with.
* `opts.name` (string)(**required**) - token name.
* `opts.symbol` (string)(**required**) - token symbol.
* `opts.maxSupply` (number) - maximum supply for this token (0 for unlimited; 1 for unique; 2 or more for multiple editions). Required to create master edition and copies with limited supply.
* `opts.amount` (string) - token amount to be first minted. Required only if maxSupply is 0 or undefined.
* `opts.uri` (string)(**required**) - URI containing NFT metadata.
* `opts.creators` (array of SolanaCreators)(**optional**) - list of creators.
* `opts.royaltiesFee` (number)(**optional**) - royalties fee.
* `opts.collection` (string)(**optional**) - collection address.

This function returns the token address.

Examples:

```javascript
// Creating NFT with master edition and max supply of 10 copies
const { hash } = await sdk.nft.create({
  protocol: 'SOLANA',
  wallet,
  name: 'NFT',
  symbol: 'NFT',
  uri: 'https://....',
  maxSupply: '10',
})
// Creating NFT without master edition and no max supply
const { hash } = await sdk.nft.create({
  protocol: 'SOLANA',
  wallet,
  name: 'NFT',
  symbol: 'NFT',
  uri: 'https://....',
  amount: '100000',
})
```

### Mint NFTs

Mint an additional amount of an existing token.

**`sdk.nft.mint(opts)`**

* `opts.protocol` (string)(**required**) - blockchain protocol must be `SOLANA`.
* `opts.wallet` (Wallet)(**required**) - wallet to sign the transaction with.
* `opts.token` (string)(**required**) - token address to be minted. If this token is a master edition, this is the address of the master edition token that will be used to create copies (editions).
* `opts.destination` (string)(**required**) - destination address.
* `opts.amount` (string) - amount to be minted. Required if this token doesn't have a master edition, leave it undefined otherwise.

This function returns the hash of the transaction.

Example:

```javascript
const { hash } = await sdk.nft.mint({
  wallet: wallets.solana,
  protocol: 'SOLANA',
  token: 'EzqZ...qnCNd',
  destination: 'Er8d....Wud3',
  amount: '1',
})
```

### Burn NFTs

**`sdk.nft.burn(opts)`**

* `opts.protocol` (string)(**required**) - blockchain protocol must be `SOLANA`.
* `opts.wallet` (Wallet)(**required**) - wallet to sign the transaction with.
* `opts.token` (string)(**required**) - address of the token that will be burned.
* `opts.amount` (string)(**required**) - token amount to be burned (no decimals).

This function returns the hash of the transaction.

Example:

```javascript
const { hash } = await sdk.nft.burn({
  protocol: 'SOLANA',
  wallet,
  token: 'EzqZ...qnCNd',
  amount: '100',
})
```

### Update NFT Metadata

**`sdk.transaction.updateSolanaNFTMetadata(opts)`**

* `opts.wallet` (Wallet)(**required**) - wallet to sign the transaction with.
* `opts.token` (string)(**required**) - address of the token that will be updated.
* `opts.uri` (string)(**required**) - uri containing the updated NFT metadata.

```javascript
const transaction = await sdk.transaction.updateSolanaNFTMetadata({
  wallet,
  token: '5N6t...3knE9',
  uri: 'https://gateway.pinata.cloud/ipfs/zyx...dcba',
})

const { hash } = await txController.sendTransaction(transaction)
// Log transaction hash
console.log(hash)
```

</details>

### **How do NFTs work on Solana?**&#x20;

Solana NFTs use the [Metaplex](https://www.metaplex.com/) Standard to add metadata information to regular SPL Tokens.&#x20;

{% hint style="info" %}
*SPL stands for Solana Program Library, which is a collection of on-chain programs that interact with the Solana blockchain.*
{% endhint %}

You can think of SPL Tokens as equivalent to Ethereum's **ERC-20** tokens. The Metaplex protocol is responsible for adjoining extra data onto these ERC-20-like tokens, effectively making them NFTs. If their max supply is set to 1, then it can be seen as an **ERC-721** token. For higher or unlimited supplies the NFT can be compared to an **ERC-1155** token. But in the end, they're the same thing!

### **What do I need in order to mint an NFT?**

A Cryptum API key is the only requirement to create your brand new NFT for Solana. However, you probably want to add images, titles, symbols, attributes, etc. to your token. This information should be hosted in a service like [Pinata](https://www.pinata.cloud/) or [arweave](https://www.arweave.org/), and not on the token itself.

For this example, we'll suppose you already managed to upload a JSON object to Pinata according to the Metaplex standard:

| Field                      | Type    | Description                                                                    |
| -------------------------- | ------- | ------------------------------------------------------------------------------ |
| name                       | string  | Name of the asset.                                                             |
| symbol                     | string  | Symbol of the asset.                                                           |
| uri                        | string  | URI to the external JSON representing the asset                                |
| creators                   | array   | public key of each creator                                                     |
| update\_authority          | string  | public key of the metadata owner                                               |
| primary\_sale\_happened    | boolean | flag describing whether the primary sale of the token happened                 |
| seller\_fee\_basis\_points | number  | royalties percentage awarded to creators                                       |
| description                | string  | Description of the asset.                                                      |
| image                      | string  | URI pointing to asset image.                                                   |
| animation\_url             | string  | URI pointing to asset animation.                                               |
| external\_url              | string  | URI pointing to an external url defining the asset, the game's main site, etc. |
| attributes                 | array   | Array of attributes defining the characteristics of the asset.                 |

Make sure to check the latest specifications in the official Metaplex documentation [here](https://docs.metaplex.com/token-metadata/v1.1.0/specification).

### ​Creating NFTs **Programmatically with Cryptum SDK** <a href="#jump" id="jump"></a>

<mark style="color:purple;">**Step 1**</mark>

The first prerequisite you will need is the creation of an **account** and a **Project (API Key**) on Cryptum Dashboard.

**PS**: Our dashboard is almost ready! To generate an API Key, contact <hello@blockforce.in>

<mark style="color:purple;">**Step 2**</mark>

With a valid Cryptum API Key, you can then instantiate the SDK as follows:

```javascript
const CryptumSdk = require('cryptum-sdk')

const sdk = new CryptumSdk({
  environment: 'testnet',  // 'testnet', 'mainnet'
  apiKey: "YOUR-API-KEY-HERE",
})
```

<mark style="color:purple;">**Step 3**</mark>

Towned to create the NFTs:

```javascript
const wallet = await sdk.wallet.generateWallet({
    protocol: 'SOLANA',
    mnemonic: 'lorem ipsum dolor sit amet consectetur adipiscing.....',
    derivation: { account: 0, address: 0 }
})
```

{% hint style="info" %}
*Make sure the wallet has sufficient funds to pay for the transactions.*
{% endhint %}

<mark style="color:purple;">**Step 4**</mark>

Call `sdk.nft.create` function passing your wallet, the desired supply, and the URI to create NFT with limited supply and a [master edition](https://docs.metaplex.com/about/terminology#master-edition).

```javascript
// Creating NFT with master edition and max supply of 10 copies
const { hash } = await sdk.nft.create({
  protocol: 'SOLANA',
  wallet,
  name: 'NFT',
  symbol: 'NFT',
  uri: 'https://....',
  maxSupply: '10',
  creators: [{ address: 'Er...4h', share: 10, verified: true }],  // optional
  royaltiesFee: 10, // optional
  collection: null // optional
})
```

{% hint style="info" %}
`name` is the token name;\
`symbol` is the token symbol;\
`uri` is the metadata URI;\
`maxSupply` is the maximum supply for this NFT (0 for unlimited; 1 for unique; 2 or more for multiple editions). Required if you want to create a master edition and copies with limited supply;\
`amount` is the NFT amount to be first minted. Required only if `maxSupply` is 0 or undefined;\
`creators` is an optional parameter which consists of an array of creator information;\
`royaltiesFee` is an optional parameter which represents a fee in percentage;\
`collection` is an optional collection address;
{% endhint %}

To create NFT without limited supply and master edition do this:

```javascript
// Creating NFT without master edition and no max supply
const { hash } = await sdk.nft.create({
  protocol: 'SOLANA',
  wallet,
  name: 'NFT',
  symbol: 'NFT',
  uri: 'https://....',
  amount: '100000'
})
```

There you go! The `hash` variable now holds the token address, which you can inspect in an explorer such as [this one](https://explorer.solana.com/) or [this other one](https://solscan.io/).

### Minting NFTs

To mint more NFTs on Solana you have to pass the wallet with the token's mint authority, the token address, destination address and the amount.

{% hint style="warning" %}
The `amount` must be 1 or `null` if this NFT has a master edition.
{% endhint %}

```javascript
const { hash } = await sdk.nft.mint({
    wallet,
    protocol: 'SOLANA',
    token: 'TOKEN_ADDRESS',
    destination: 'Hvm.....9Gxe',
    amount: '11'
})
```

### Transferring NFTs

To transfer NFTs in Solana, just pass the token address, token address, the destination address and the amount:

```javascript
const { hash } = await sdk.nft.transfer({
    wallet: wallets.solana,
    protocol: 'SOLANA',
    token: 'TOKEN_ADDRESS',
    amount: '2',
    destination: 'DohbPo7UF.....94hmj2ohr'
})
```

### Burning NFTs

To burn NFTs on Solana you have to pass the wallet that owns the NFT, the token address and the amount:

```javascript
const { hash } = await sdk.nft.burn({
  protocol: 'SOLANA',
  wallet,
  token: 'EzqZ...qnCNd',
  amount: '100',
})
```

If you want to check the full Solana NFTs doc, go to:

{% embed url="<https://github.com/blockforce-official/cryptum-sdk/blob/master/docs/nfts/solana.md>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cryptum.io/english/community-edition/sdk-guides/nfts/nfts-on-solana.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
