Skip to content

Creating a Solana Crypto Token

Solana is a fast, proof-of-history token framework with a Rust language ‘contract’ system.

I created a couple of Solana tokens. Here’s how…

Steps:

  • Download Solana platform and the SPL CLI:

    sh -c "$(curl -sSfL https://release.solana.com/v1.10.23/install)" (See the Solana Installations Docs for details.

  • Install Rust
  • Install the Solana token CLI (cargo install spl-token-cli)
  • Mint a new token
  • Create an icon
  • Register the token on github. (Solana token registry)

I’ve made a very lightweight docker image here with the appropriate tools and some helpful scripts for playing around with tokens. You can go through the token creation process below using this container.

Creating a fungible Solana token

To do a test run first, switch to a test net:

$ solana config get
Config File: /root/.config/solana/cli/config.yml
RPC URL: https://api.mainnet-beta.solana.com
WebSocket URL: wss://api.mainnet-beta.solana.com/ (computed)
Keypair Path: /root/.config/solana/id.json
Commitment: confirmed
$ solana config set --url https://api.devnet.solana.com
Config File: /root/.config/solana/cli/config.yml
RPC URL: https://api.devnet.solana.com
WebSocket URL: wss://api.devnet.solana.com/ (computed)
Keypair Path: /root/.config/solana/id.json
Commitment: confirmed

Later, when you want to create real tokens on the mainnet, you can set the RPC URL back to it’s original value:

$ solana config set --url https://api.mainnet-beta.solana.com

Also, create an encryption key pair:

$ solana-keygen new  -o /root/.config/solana/id.json

This will create a new key pair. Make a note of the BIP39 passphrase used, and the seed phrase. The private key is stored in plaintext, and is thus very insecure. Don’t leave that plaintext file hanging around, or don’t store anything of value in this wallet.

Once you have the passphrase and seedphrase stored, you can regenerate your key pair at any time with:

$ solana-keygen recover --force prompt://
<enter the seed phrase>
<enter the passphrase twice>

You could also store your keys in a hardware wallet like ledger.

$ solana-keygen pubkey usb://ledger

However, USB passthrough with docker on a Mac is not straightforward, so I’m not doing that. If you want to, it’s possible, but apparently you need to ditch docker desktop (which uses Hyperkit, which doesn’t support USB passthrough) and use a KVM like VirtualBox.

Anyway, the next step is to ensure that the public key displayed matches your original public key.

$ solana address
2ASn1atx6oHF4vkyF9vEBBMreJPcaXEiaiFieah9vyZK

Then, send yourself some SOL. You’ll need it to pay for the proceeding transactions. On the testnet, you can airdrop yourself some:

$ solana airdrop 1
Requesting airdrop of 1 SOL

Signature: 4qGBTAcuo8g728CXE5mmn3447vfhBSzs9EmzKh5p25ZK1P9feJ1j3P8ekmfieXYSbT6A8XusderoPU7ceVfA8oCd

1 SOL
$ solana balance
1 SOL

So, you received 1 SOL, and the Signature returned refers to the blackchain transaction ID where your airdrop occured. You can search for this with the Solana blockchain explorer. That link points to the mainnet blockchain, but there is a button on the page to choose testnet or devnet.

1 SOL is far more than you need to pay for the transactions and account rents involved here.

On the mainnet, you’ll need to buy some on an exchange. I used Coinbase.

You can quickly check your account details:

$ solana account 2ASn1atx6oHF4vkyF9vEBBMreJPcaXEiaiFieah9vyZK

Public Key: 2ASn1atx6oHF4vkyF9vEBBMreJPcaXEiaiFieah9vyZK
Balance: 1 SOL
Owner: 11111111111111111111111111111111
Executable: false
Rent Epoch: 321

Now to create a new Solana token! I wanted to create a fungible token with 2 decimal places:

$ spl-token create-token --decimals 2        # 9 is default
Creating token DmSx9d931vZt4HLZ6c4Cyt3ka3EAC2mmeD6JEfgCeQoQ

Signature: 4KLmXg4TPbsp9N1xGgXLFErPDjcipGLsbgNmpgkr6NdM2jjy5TKRJjqZeQJB2NrHyzRjrb9BEHRKKLwXrLhrWHJQ

This creates the token and reports the token unique identifier. You’ll need that later. Again, the signature is the ID of the transaction on the blockchain which created your new token

Next, create an account for your new token:

$ spl-token create-account DmSx9d931vZt4HLZ6c4Cyt3ka3EAC2mmeD6JEfgCeQoQ
Creating account EnrMVfUNHMotdNAxjzjPakvPXYRG7xggsE78z6z5U6ps

Signature: L5H13wni3i1sfRWu2qYJSiR46re8PWU8taoCSBBFLWK5fXEB29Gf4YGfK4C3oXRMa2RLvnyamBrQa6Z4iB4paXP

Mint a bunch of tokens, and add them to your new account:

# spl-token mint <token ID> <amount> [optional account address]
$ spl-token mint DmSx9d931vZt4HLZ6c4Cyt3ka3EAC2mmeD6JEfgCeQoQ 1000000000000
Minting 1000000000000 tokens
  Token: DmSx9d931vZt4HLZ6c4Cyt3ka3EAC2mmeD6JEfgCeQoQ
  Recipient: EnrMVfUNHMotdNAxjzjPakvPXYRG7xggsE78z6z5U6ps

Signature: afM8He5RBtXVLSJhiW3m52YEj7iJc2qvBToxrQBp999p1QdAH2yA7gEySpQTRmK2NTZ7gZABh8QC6hUsmTu8P6r

Verify the token supply:

$ spl-token supply DmSx9d931vZt4HLZ6c4Cyt3ka3EAC2mmeD6JEfgCeQoQ
18446744073.709551615

Note that the amount minted is i) measured in increments of whatever the decimal value the token has been created with, and ii) a maximum of a u64 bit integer. So in this case, I had created a token with 9 decimal places. That meant that it reached the u64 representation limit, and produced just as many tokens as it could.

Now, check your balances and account details:

$ spl-token balance DmSx9d931vZt4HLZ6c4Cyt3ka3EAC2mmeD6JEfgCeQoQ
18446744073.709551615

$ solana balance
0.99647912 SOL
$ solana account DmSx9d931vZt4HLZ6c4Cyt3ka3EAC2mmeD6JEfgCeQoQ

Public Key: DmSx9d931vZt4HLZ6c4Cyt3ka3EAC2mmeD6JEfgCeQoQ
Balance: 0.0014616 SOL
Owner: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
Executable: false
Rent Epoch: 321
Length: 82 (0x52) bytes
0000:   01 00 00 00  68 fa 77 ea  11 06 fd c3  10 ec 82 59   ....h.w........Y
0010:   4a 2d e0 a3  50 c0 9b 5d  36 3b e1 d4  87 4b 20 32   J-..P..]6;...K 2
0020:   95 43 6c 1e  ff ff ff ff  ff ff ff ff  09 01 00 00   .Cl.............
0030:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
0040:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
0050:   00 00                                                ..

Now you can transfer your SOL and tokens to other accounts

$ solana transfer --allow-unfunded-recipient 2ASn1atx6oHF4vkyF9vEBBMreJPcaXEiaiFieah9vyZK 0.15

OMG! I now have 0.15 SOL in my account, and am now a god among men!

# spl-token transfer <options> <token ID> <amount> <recipient address>
$ spl-token transfer --allow-unfunded-recipient --fund-recipient DmSx9d931vZt4HLZ6c4Cyt3ka3EAC2mmeD6JEfgCeQoQ 1000 2ASn1atx6oHF4vkyF9vEBBMreJPcaXEiaiFieah9vyZK

If the address you want to send tokens to isn’t already funded, you can fund it as part of the transaction.

There you go! Now you have SOL and tokens in any account you want. Hooray!

If you use Ledger, your ledger live software doesn’t currently show Solana tokens. You’ll need to use, say, Solflare. Then authenticate your account by connecting your Ledger device. Solflare can then display the correct token balances!

Finishing Touches

You can register your token, and provide an icon, by providing some basic details to the (Solana token registry). Simply add edit the token list file submit a pull request. The PR should be automatically closed and merged by a bot within about an hour.

References

How to Create a Solana Token in 5 Steps » Moralis » The Ultimate Web3 Development Platform

Create and List a Solana Token in a UI with Zero Development in 5 Minutes