0

I have utilised the Solana CLI to handle the upgrade authority for my program. However, I now require the ability to update the upgrade authority using JavaScript. Is there a way to achieve this?

1 Answer 1

1

There certainly is! I took a look around, and since I know that the governance program is typically used to upgrade other programs, I found the instruction in its UI code:

export async function createSetUpgradeAuthority(
  programId: PublicKey,
  upgradeAuthority: PublicKey,
  newUpgradeAuthority: PublicKey
) {
  const bpfUpgradableLoaderId = BPF_UPGRADE_LOADER_ID

  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
  })
}

Found at https://github.com/solana-labs/governance-ui/blob/1b4df7486f45ad8c42771c5d4b5877843ffe788a/tools/sdk/bpfUpgradeableLoader/createSetUpgradeAuthority.ts

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.