I implemented a program and I checked the authority's publickey address. how can i get this wallet address (for example i want a fn number in the code that can only be called with authority). Or is there a way I can update the authority again after deploying. Thank you.
2 Answers
If you didn't provide the authority during the deployment of the program then it was deployed using your default keypair. The secret key of the default keypair is saved in id.json
file in the root of your solana
folder.
Meanwhile, you can also update the upgrade authority of the program using:
solana program set-upgrade-authority <PROGRAM_ADDRESS> --new-upgrade-authority <NEW_UPGRADE_AUTHORITY>
You can't validate the upgrade authority directly within the program. If you want to restrict the calling of an instruction solely to the upgrade authority, the best way to do that would be to hardcode the upgrade authority in your program.
If you know the exact key you want to validate against (in this case you do, since it's the publickey of the keypair you used to deploy), you can do a simple constraint check for the key, and make sure that account is a signer, which means that whoever invoked it must be private key holder:
#[derive(Accounts)]
pub struct SomeContext<'info> {
#[account(address = some_key)]
pub signer: Signer<'info>,
}