4

I want to create my SPL token and upload it to https://github.com/solana-labs/token-list. But I found only articles with no-code solution: https://learn.figment.io/tutorials/sol-mint-token or using metaplex.

I want to leave creating my token with full control over its distribution etc.

1 Answer 1

6

Great question! I was stuck there as well some time ago.

In order to show people how it works, I've created a quick repo on github.

The way it works is: You mint your token using something like:

pub struct MintCtrl<'info> {
    #[account(init_if_needed, payer = payer, seeds = [CTRLSEED.as_ref()], bump, mint::decimals = 6, mint::authority = mint)]
    pub mint: Account<'info, Mint>,
    #[account(init_if_needed, payer = payer, associated_token::mint = mint, associated_token::authority = payer)]
    pub destination: Account<'info, TokenAccount>,
    #[account(mut)]
    pub payer: Signer<'info>,
    pub system_program: Program<'info, System>,
    pub token_program: Program<'info, Token>,
    pub associated_token_program: Program<'info, AssociatedToken>,
    pub rent: Sysvar<'info, Rent>,
}

Then, in order to have a ticker symbol and logo associated with your token, you have to add metadata.

    pub fn tok_meta(ctx: Context<TokMeta>, bump: u8) -> Result<()> {
       let ix = create_metadata_accounts_v2(
            *ctx.accounts.metadata_program.to_account_info().key, // program_id,
            *ctx.accounts.metadata_pda.to_account_info().key, // metadata_account,
            *ctx.accounts.mint.to_account_info().key, //mint,
            *ctx.accounts.mint.to_account_info().key, //mint_authority,
            *ctx.accounts.payer.to_account_info().key, //payer,
            *ctx.accounts.updauth.to_account_info().key, //update_authority,
            String::from("CTRL - Program Controlled Token"), // name,
            String::from("CTRL"), // symbol,
            String::from("https://bernieblume.github.io/Ctrl/Ctrl.json"), // uri,
            None, // creators,
            0u16, //seller_fee_basis_points,
            false, // update_authority_is_signer,
            true, // is_mutable,
            None, // collection,
            None, // uses,
            // for create_metadata_accounts_v3, add:     None, // collection_details
        );
        invoke_signed(
            &ix,
            &[
                ctx.accounts.metadata_program.to_account_info().clone(), // Metadata program id
                ctx.accounts.metadata_pda.to_account_info().clone(), // Metadata account
                ctx.accounts.mint.to_account_info().clone(), // Mint
                ctx.accounts.mint.to_account_info().clone(), // Mint Authority
                ctx.accounts.payer.to_account_info().clone(), // Payer
                ctx.accounts.updauth.to_account_info().clone(), // Update Authority
                ctx.accounts.system_program.to_account_info().clone(), // System Program
                ctx.accounts.rent.to_account_info().clone(), // Rent Sysvar
            ],
            &[
                &[CTRLSEED.as_ref(), &[bump]],
            ],
        )?;
        Ok(())
    }

You can find the full github repo here.

5
  • My thanks! 1) Then I write all the functions for minting, transferring, burning, etc. myself? 2) And this coin will also be visible in devnet and mainnet?
    – Watchman
    Commented Aug 13, 2022 at 7:55
  • Yes you write these functions yourself, but each is just a few lines of code. It's calling Metplex's TokenMetadataProgram with the right set of parameters. Commented Aug 13, 2022 at 16:30
  • Whatever you do in Devnet will only be visible in Devnet. Whatever you do in Mainnet, will only be visible in Mainnet. So you run your code on Devnet, and when it's ready for prime time, you run it again on Mainnet. Commented Aug 13, 2022 at 16:32
  • have a problem, when I tested the set meta function, I got a very strange error: Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: instruction expected an executable account
    – Watchman
    Commented Aug 16, 2022 at 10:21
  • Did that happen when you tried on Devnet? You need to deploy your program to Devnet before you can send transactions there... Same for localhost/localnet. And of course also for mainnet, but it seems you have deployed there already. Commented Aug 16, 2022 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.