设置权限说明
更改 mint 或账户的权限。这允许转移所有权或更新特定的权限类型。
在我们设置任何代币或代币账户的权限之前,我们需要已经完成以下操作:
- 初始化一个我们持有
mintAuthority
或freezeAuthority
的Mint
账户 - 初始化一个我们拥有的
Token
账户或Associated Token
账户
以下是 CPI 到 set_authority()
指令的示例:
set_authority(
CpiContext::new(
ctx.accounts.token_program.to_account_info(),
SetAuthority {
account_or_mint: ctx.accounts.mint_account.to_account_info(),
to: ctx.accounts.to_token_account.to_account_info(),
current_authority: ctx.accounts.authority.to_account_info(),
},
),
&spl_token::instruction::AuthorityType::MintTokens, // authority_type
Some(new_authority.key()) // new_autority
)?;