const [programDataAddress] = PublicKey.findProgramAddressSync(
[programId.toBuffer()],
BPF_LOADER_UPGRADEABLE_ID
);
const programDataAccountMeta: AccountMeta = {
pubkey: programDataAddress,
isSigner: false,
isWritable: true,
};
const modifyProgramDataInstruction = new TransactionInstruction({
programId,
data: Buffer.from(serialize(modifyProgramData)),
keys: [programDataAccountMeta],
});
let transaction = new Transaction();
transaction.add(modifyProgramDataInstruction)
//sign and send transaction with phantom
1 Answer
There's a lot to unpack here!
From Phantom, or any wallet, you can send any transaction that you want to the network, targeting any program.
For the loader program, I'm not sure what you're trying to do exactly, but it's not possible to just modify program data in place. If you want to change a program, you must create a new "buffer" account, write the program to that buffer, and then upgrade the existing program with the buffer account. You can read more about deploying programs at https://docs.solana.com/developing/on-chain-programs/deploying
Since you must write the entire program into an on-chain account, and transactions are capped at 1232 bytes, it may take thousands of transactions to upload the program. For that reason, a web wallet like Phantom will be practically impossible to use, unless you want to click "approve" thousands of times!
Separately, it doesn't look like your modifyProgramData
instruction will work as is, however, since you're only passing in the program data account. No instructions to the upgradeable loader take only one account. You can see them all at https://github.com/solana-labs/solana/blob/13107b4eb69120f672896f48d77affa9df45e8b4/sdk/program/src/loader_upgradeable_instruction.rs