2

How can I ensure that a function can only be called by the address that deployed the program, or the address that is the mint authority ? In anchor

1 Answer 1

2

You can do it like this for example:

const ADMIN_PUBKEY: Pubkey = pubkey!("REPLACE_WITH_YOUR_WALLET_PUBKEY");

And then use it like this:

#[account(
        mut,
        address = ADMIN_PUBKEY
    )]
    pub admin: Signer<'info>,

    // The PDA is both the address of the mint account and the mint authority
    #[account(
        init,
        seeds = [b"reward"],
        bump,
        payer = admin,
        mint::decimals = 9,
        mint::authority = reward_token_mint,

    )]
    pub reward_token_mint: Account<'info, Mint>,

Here is an example: https://beta.solpg.io/tutorials/battle-coins

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