I would like to initialize in my Anchor program a reward token to mint it when the user create a new movie review:
use anchor_lang::prelude::*;
use anchor_spl::token::{mint_to, MintTo, Mint, TokenAccount, Token};
use anchor_spl::associated_token::AssociatedToken;
use anchor_lang::solana_program::program::invoke_signed;
use mpl_token_metadata::instruction::create_metadata_accounts_v3;
declare_id!("A54JaBpNgAnocNmK3Axa9Teq5SxrAXTmVHgM5NV7hZrX");
#[program]
pub mod solana_movies_tokens {
use super::*;
pub fn add_movie_review(ctx: Context<AddMovieReview>, title: String, description: String, rating: u8) -> Result<()> {
let movie_review = &mut ctx.accounts.movie_review;
movie_review.reviewer = ctx.accounts.initializer.key();
movie_review.title = title;
movie_review.description = description;
movie_review.rating = rating;
mint_to(
CpiContext::new_with_signer(
ctx.accounts.token_program.to_account_info(),
MintTo {
authority: ctx.accounts.mint.to_account_info(),
to: ctx.accounts.token_account.to_account_info(),
mint: ctx.accounts.mint.to_account_info()
},
&[&[
b"mint",
&[*ctx.bumps.get("mint").unwrap()]
]]
),
10*10^6
)?;
msg!("Minted tokens");
Ok(())
}
pub fn initialize_token_mint(ctx: Context<InitializeMint>) -> Result<()> {
msg!("Token mint initialized");
Ok(())
}
}
#[derive(Accounts)]
#[instruction(title: String, description: String)]
pub struct AddMovieReview<'info> {
#[account(
init,
seeds=[title.as_bytes(), initializer.key().as_ref()],
bump,
payer = initializer,
space = 8 + 32 + 1 + 4 + title.len() + 4 + description.len()
)]
pub movie_review: Account<'info, MovieAccountState>,
#[account(mut)]
pub initializer: Signer<'info>,
pub system_program: Program<'info, System>,
pub token_program: Program<'info, Token>,
#[account(
seeds=[b"mint"],
bump,
mut
)]
pub mint: Account<'info, Mint>,
#[account(
init_if_needed,
payer = initializer,
associated_token::mint = mint,
associated_token::authority = initializer
)]
pub token_account: Account<'info, TokenAccount>,
pub associated_token_program: Program<'info, AssociatedToken>,
pub rent: Sysvar<'info, Rent>
}
#[derive(Accounts)]
pub struct InitializeMint<'info> {
#[account(
init,
seeds = [b"mint"],
bump,
payer = user,
mint::decimals = 6,
mint::authority = mint,
)]
pub mint: Account<'info, Mint>,
#[account(mut)]
pub user: Signer<'info>,
pub token_program: Program<'info, Token>,
pub rent: Sysvar<'info, Rent>,
pub system_program: Program<'info, System>,
}
#[account]
pub struct MovieAccountState {
pub reviewer: Pubkey,
pub rating: u8,
pub title: String,
pub description: String,
}
This code works, but I don't know how I can set a logo, name, and symbol to my token. I would like to set this information in the same program.