1

Normally we create minter / token on program, thereafter, the program owns the mint authority, for example:

#[derive(Accounts)]
#[instruction(symbol: String, decimals: u8)]
pub struct AddToken<'info> {
    #[account(
        mut,
        constraint = admin.key() == ADMIN_ACCOUNT,
    )]
    pub admin: Signer<'info>,

    // The PDA is both the address of the mint account and the mint authority
    #[account(
        init_if_needed,
        seeds = [symbol.as_bytes()],
        bump,
        payer = admin,
        mint::decimals = decimals,
        mint::authority = mapping_token_mint,
    )]
    pub mapping_token_mint: Account<'info, Mint>,
            
    // ... 
    pub token_program: Program<'info, Token>,
    pub system_program: Program<'info, System>, 
}

What if there is a minter created by cli and it mint authority is a wallet?

How can I transfer all authority to contract program ? Are Update Authority, Mint Authority the complete authority list to tranfer to program?

I want the minter is fully transfer to program without any right remain in wallet account.

Can anybody show my how to or provide some source link?

//Edit1: @Jimii provide a JS approach. But later on, I found I need rust contract method to archive this, because I need to register the minter and check if the supply is zero.

Thanks

1 Answer 1

2

If you created a token using the CLI, you can assign a PDA/new address as the mint account's authority (freeze and mint).

In Typescript using the @solana/spl-token package

// transfer mint and freeze authorities
async function TransferAuth() {
    let mint = new PublicKey("");

    const newAuthority = new PublicKey("");

    // hand over freeze authority
    let freezeAuthIx = createSetAuthorityInstruction(
        mint,
        signer.publicKey,
        AuthorityType.FreezeAccount,
        newAuthority
    );

    // hand over mint authority
    let mintAuthIx = createSetAuthorityInstruction(
        mint,
        signer.publicKey,
        AuthorityType.MintTokens,
        newAuthority
    );

    const tx = await new Transaction().add(freezeAuthIx).add(mintAuthIx);
    let txHash = await sendAndConfirmTransaction(conn, tx, [signer]);
    console.log(txHash);
}

You can also update the metadata UpdateAuthority using Metaplex UMI and mpl-token-metadata package

    await updateV1(umi, {
        mint,
        authority: umi.identity,
        data: { ...onChainMetadata, name: newName },
        primarySaleHappened: true,
        newUpdateAuthority: publicKey(newAuthority.toBase58()),
        isMutable: true,
    }).sendAndConfirm(umi);

ref: https://developers.metaplex.com/token-metadata/update#new-update-authority

1
  • 1
    wow, great examples, I will try it soon. Commented Nov 22 at 8:52

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.