# Solana Tokens (SPL)

<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 tokens

Solana tokens follow the SPL Token standard alongside the Metaplex NFT protocol.

#### `sdk.token.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.amount` (string)(**required**) - token amount to be first minted.
* `opts.fixedSupply` (boolean)(**required**) - whether future minting will be restricted or not.
* `opts.decimals` (number)(**required**) - amount of decimal units for this token.

This function returns hash of the token created.

```javascript
const { hash } = await sdk.token.create({
  protocol: 'SOLANA',
  wallet,
  symbol: 'TEST',
  name: 'TEST',
  amount: '1000000',
  fixedSupply: false,
  decimals: 9,
})
```

### Mint tokens

Mint an additional amount of an existing token.

**`sdk.token.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**) - address of the token that will be minted.
* `opts.amount` (string)(**required**) - token amount to be minted.
* `opts.destination` (string)(**required**) - destination address.

This function returns the hash of the minting transaction.

```javascript
const { hash } = await sdk.token.mint({
  wallet,
  protocol: 'SOLANA',
  token,
  amount: '20.42',
  destination: 'DohbPo7UFV6phQ9DJF...psM2uwLQxEj94hmj2ohr',
})
```

### Burn tokens

**`sdk.token.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.

This function returns the hash of the burning transaction.

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

</details>

**I**n order to create a currency on top of the Solana blockchain, we must use the token program provided by the Solana Program Library (which is why they are called **SPL** tokens). The program source code can be found [here](https://github.com/solana-labs/solana-program-library/tree/master/token), although previous knowledge of how it works is not necessary to proceed with this guide.

### Differences Between ERC-20 and SPL Tokens <a href="#differences-between-erc-20-and-spl-tokens" id="differences-between-erc-20-and-spl-tokens"></a>

For currencies to be created on the Ethereum blockchain, you must deploy a smart contract containing the workings of the token you wish to create – usually following a standard such as the ERC-20 one. For Solana, however, there is already a “coin factory” program provided by the official team and all we have to do is pass the correct instructions to this program.

{% hint style="info" %}
In Solana smart contracts are called **programs** instead!
{% endhint %}

### Creating a New Token <a href="#creating-a-new-token-mint" id="creating-a-new-token-mint"></a>

#### <mark style="color:purple;">Step 1</mark> <a href="#step-1" id="step-1"></a>

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> <a href="#step-2" id="step-2"></a>

Supposing you already installed our SDK available on GitHub [here](https://github.com/blockforce-official/cryptum-sdk), all we need to do is create instantiate it like this:

```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> <a href="#solana" id="solana"></a>

Then you must instantiate the wallet that will be used to create the tokens:

```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> <a href="#step-4" id="step-4"></a>

The fourth step consists of creating the token passing the wallet variable you just created alongside some other arguments:

```javascript
const { hash } = await sdk.token.create({
    protocol: 'SOLANA',
    wallet: wallets.solana,
    symbol: 'TEST',
    name: 'TEST',
    amount: '1000000',
    fixedSupply: false,
    decimals: 9
})
```

{% hint style="info" %}
The “*wallet*” will receive the newly minted tokens;\
”*fixedSupply*” defines whether future minting is restricted or not;\
”*decimals*” is the number of decimal units for this token (at most 9);\
“*amount*“ refers to the token amount to be first minted;
{% endhint %}

The wallet now holds all the new tokens and the `hash` variable contain the token address, which can be inspected in an explorer such as [this one](https://explorer.solana.com/) or [this other one](https://solscan.io/).

### Other Functionalities

Besides deploying a token, you can also mint or burn existing tokens.

#### <mark style="color:purple;">Minting Tokens</mark> <a href="#minting-tokens" id="minting-tokens"></a>

If you’re the token’s Mint Authority, then you can mint extra tokens like this:

```javascript
const { hash } = await sdk.token.mint({
    wallet:,
    protocol: 'SOLANA',
    token: 'TOKEN_ADDRESS_FROM_PREVIOUS_STEP',
    amount: 20,
    destination: 'DohbPo7UFV6....wLQxEj94hmj2ohr'
})
```

#### <mark style="color:purple;">Burning Tokens</mark> <a href="#burning-tokens" id="burning-tokens"></a>

Unlike minting, anybody can burn the tokens they own.

```javascript
const { hash } = await sdk.token.burn({
    wallet,
    protocol: 'SOLANA',
    token: 'TOKEN_ADDRESS_FROM_PREVIOUS_STEP',
    amount: '5',
})
```

#### <mark style="color:purple;">Transfer Tokens</mark> <a href="#transfer-tokens" id="transfer-tokens"></a>

To transfer tokens between accounts, use this function:

```javascript
const { hash } = await sdk.token.transfer({
    wallet,
    protocol: 'SOLANA',
    token: 'TOKEN_ADDRESS_FROM_PREVIOUS_STEP',
    amount: '0.019',
    destination: 'DohbPo7UFV6p.....xEj94hmj2ohr'
})
```

{% hint style="warning" %}
Note that the ‘amount’ field takes decimal units into account. For example: the token we created in this guide has two decimal units, so to transfer 20 tokens the amount variable is 20.
{% endhint %}

{% hint style="info" %}
The 'token' field can be any custom token available in the blockchain and also the native token in Solana. To transfer native tokens just pass "SOL" as the token.&#x20;
{% endhint %}


---

# 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/tokens/solana-tokens-spl.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.
