2

I want to get the owner account in Solana program written using anchor, however I didn't find any method by which I can find the owner the way we have in Ethereum. Can someone help me to find the owner in Solana Program.

1

1 Answer 1

3

If by "owner" you mean the upgrade authority of a program, then you can get the account data of the program and deserialize those bytes with:

async function getProgramAuthority(c: Connection, programId: PublicKey): Promise<PublicKey> {
  const info = await c.getAccountInfo(programId)
  const dataAddress = new PublicKey(info.data.subarray(4))

  const dataAcc = await c.getAccountInfo(dataAddress)
  return new PublicKey(dataAcc.data.subarray(13, 45))
}

This is an optional field though, so if dataAcc.data[12] === 1 then the next 32 bytes [13:45] will be the upgrade authority, otherwise there is no active upgrade authority and the program is immutable.

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.