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 Answer
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.