Solana Tokens (SPL)

Straight to the code!

Instantiate Cryptum SDK first:

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.

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.

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.

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

In 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, although previous knowledge of how it works is not necessary to proceed with this guide.

Differences Between ERC-20 and SPL Tokens

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.

In Solana smart contracts are called programs instead!

Creating a New Token

Step 1

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

Step 2

Supposing you already installed our SDK available on GitHub here, all we need to do is create instantiate it like this:

const CryptumSdk = require('cryptum-sdk')

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

Step 3

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

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

Make sure the wallet has sufficient funds to pay for the transactions.

Step 4

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

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

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;

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 or this other one.

Other Functionalities

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

Minting Tokens

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

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

Burning Tokens

Unlike minting, anybody can burn the tokens they own.

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

Transfer Tokens

To transfer tokens between accounts, use this function:

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

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.

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.

Last updated