Skip to content

Instantly share code, notes, and snippets.

@vit0rr
Created December 7, 2021 19:47
Show Gist options
  • Save vit0rr/f46074e0e86d1fddf47dadb2e13083fa to your computer and use it in GitHub Desktop.
Save vit0rr/f46074e0e86d1fddf47dadb2e13083fa to your computer and use it in GitHub Desktop.
Transfer token ownership to another account
use solana_program::{
account_info::{next_account_info, AccountInfo},
entrypoint::ProgramResult,
program_error::ProgramError,
msg,
pubkey::Pubkey,
program_pack::{Pack, IsInitialized},
sysvar::{rent::Rent, Sysvar},
program::invoke
};
// inside process_init_escrow
...
let token_program = next_account_info(account_info_iter)?;
let owner_change_ix = spl_token::instruction::set_authority(
token_program.key,
temp_token_account.key,
Some(&pda),
spl_token::instruction::AuthorityType::AccountOwner,
initializer.key,
&[&initializer.key],
)?;
msg!("Calling the token program to transfer token account ownership...");
invoke(
&owner_change_ix,
&[
temp_token_account.clone(),
initializer.clone(),
token_program.clone(),
],
)?;
Ok(())
// end of process_init_escrow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment