Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save codebender828/dbaf18b53a1aecb66e16595ca72a63b0 to your computer and use it in GitHub Desktop.
Save codebender828/dbaf18b53a1aecb66e16595ca72a63b0 to your computer and use it in GitHub Desktop.
Programmatically Change the Upgrade Authority of a Solana Program
export async function createSetUpgradeAuthority(
programId: PublicKey,
upgradeAuthority: PublicKey,
newUpgradeAuthority: PublicKey
) {
const bpfUpgradableLoaderId = new PublicKey(
"BPFLoaderUpgradeab1e11111111111111111111111"
);
const [programDataAddress] = await PublicKey.findProgramAddress(
[programId.toBuffer()],
bpfUpgradableLoaderId
);
const keys = [
{
pubkey: programDataAddress,
isWritable: true,
isSigner: false,
},
{
pubkey: upgradeAuthority,
isWritable: false,
isSigner: true,
},
{
pubkey: newUpgradeAuthority,
isWritable: false,
isSigner: false,
},
];
return new TransactionInstruction({
keys,
programId: bpfUpgradableLoaderId,
data: Buffer.from([4, 0, 0, 0]), // SetAuthority instruction bincode
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment