【发布时间】:2022-07-13 12:03:16
【问题描述】:
我的意图是拥有可以存储程序使用的数据的帐户。我将在每次调用我的链上程序时传递这个帐户。如果我尝试从 onchain 调用 allocate,则结果为 <pda-address>'s writable permission escalated
似乎拥有 PDA 是个好主意,因为只有我的程序才能使用它。但我不确定我该怎么做。这是我迄今为止尝试过的
- 在前端派生一个 PDA
- 作为其他普通账户传递
- 程序将收到的第一个 AccountInfo 视为 PDA 并使用它来存储数据
上述方法出错:
- 我需要分配空间来在 PDA 中存储数据。但由于 PDA 没有 Secret Key 并且因此没有 KeyPair,我无法调用 allocateSpace 之类的调用。
我在这里缺少什么?我是 solana 的新手,所以我什至可能错过了最简单的事情。
客户端
const deposit_instruction = new solana.TransactionInstruction({
keys: [
{ pubkey: system_account, isSigner: false, isWriteable: false },
{ pubkey: payer.publicKey, isSigner: true, isWritable: true },
{ pubkey: pdaAccount, isSigner: false, isWriteable: false },
{ pubkey: sender.publicKey, isSigner: true, isWriteable: true },
{ pubkey: receiver, isSigner: false, isWriteable: false },
],
programId: programId,
data: argument_ser,
});
return await callEntryPoint(deposit_instruction, [sender, payer]);
链上计划
let instruction = system_instruction::allocate(pda_account.key, 100u64);
invoke_signed(
&instruction,
&[pda_account.clone(), system_account.clone()],
&[&[SEED], &[&[bump]]],
)?;
【问题讨论】:
标签: javascript rust blockchain solana solana-web3js