Skip to main content
Added Accounts struct
Source Link
AllBlooming
  • 2.3k
  • 4
  • 18

PS: Here's the corresponding Accounts struct:

#[derive(Accounts)]
#[instruction(okubump: u8)]
pub struct TokMeta<'info> {
    #[account(seeds = [OKUSEED.as_ref()], bump = okubump, mint::decimals = 6, mint::authority = mint)]
    pub mint: Account<'info, Mint>,
    #[account(mut)]
    pub payer: Signer<'info>,
    /// CHECK: This is not dangerous because it's being checked by the inner instruction
    #[account(mut)]
    pub metadata_pda: AccountInfo <'info>,
    pub system_program: Program<'info, System>,
    pub token_program: Program<'info, Token>,
    pub rent: Sysvar<'info, Rent>,
}

PS: Here's the corresponding Accounts struct:

#[derive(Accounts)]
#[instruction(okubump: u8)]
pub struct TokMeta<'info> {
    #[account(seeds = [OKUSEED.as_ref()], bump = okubump, mint::decimals = 6, mint::authority = mint)]
    pub mint: Account<'info, Mint>,
    #[account(mut)]
    pub payer: Signer<'info>,
    /// CHECK: This is not dangerous because it's being checked by the inner instruction
    #[account(mut)]
    pub metadata_pda: AccountInfo <'info>,
    pub system_program: Program<'info, System>,
    pub token_program: Program<'info, Token>,
    pub rent: Sysvar<'info, Rent>,
}
edited tags
Link
AllBlooming
  • 2.3k
  • 4
  • 18
Source Link
AllBlooming
  • 2.3k
  • 4
  • 18

How to create a metadata account for a token whose mint authority is a PDA?

My token's mint authority is my Program.

I need to add metadata so that the token appears nicely in my users' wallets.

So in order to add the metadata, I need to create a new instruction into my Program, and do a CPI there.

I'm having a hard time defining all the correct parameters there.

Here's my try:

    pub fn tok_meta(ctx: Context<TokMeta>, okubump: u8) -> Result<()> {
        let (metadata_pda, _bump) = find_metadata_account(ctx.accounts.mint.to_account_info().key);
        let ix = create_metadata_accounts_v3(
            mpl_token_metadata::id(), // program_id,
            metadata_pda, // metadata_account,
            *ctx.accounts.mint.to_account_info().key, //mint,
            , //mint_authority, *** HOW TO GET MY OWN PROGRAM ID?? ***
            *ctx.accounts.payer.to_account_info().key, //payer,
            *ctx.accounts.payer.to_account_info().key, //update_authority,
            String::from("OKU - Bitoku Storage"), // name,
            String::from("OKU"), // symbol,
            String::from("https://okupub.gitlab.io/imgs/Oku.json"), // uri,
            None, // creators,
            0u16, //seller_fee_basis_points,
            true, // update_authority_is_signer,
            true, // is_mutable,
            None, // collection,
            None, // uses,
            None, // collection_details
        );
        invoke_signed(
            &ix,
            &[
                ctx.accounts.metadata_pda.to_account_info().clone(), // Metadata account
                ctx.accounts.mint.to_account_info().clone(), // Mint
                , // Mint Authority *** HOW TO GET MY OWN PROGRAM ID ***
                ctx.accounts.payer.to_account_info().clone(), // Payer
                ctx.accounts.payer.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
            ],
            &[&[&OKUSEED, &[okubump]]],
        )?;
        Ok(())
    }

}

A few burning questions here:

  1. How can I get my own ProgramID in the form of AccountInfo, so that I can pass it as an account?

  2. How can I get the metadata_pda as AccountInfo? I can get the pubkey and bump using find_metadata_account, but that doesn't get me the AccountInfo. And it's tough to pass the metadata_pda as an account to the outer instruction because it depends not on my Program_id, but on the token_metadata program's ID.

  3. Am I doing everything correctly with the signers_seeds? These are the seeds used to get from my ProgramID to the mint address. Are these the ones needed here?

  4. Are all the clone()s correct and needed?

Any help greatly appreciated!