Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 8156

Unknown signer in PDA initialization in Anchor

$
0
0

I am having a problem initializing a PDA for a program I am working on. This all all worked before I attempted to add in an authority and require a signer to prevent unauthorized access. In the past I ran this code once to establish a single PDA, and then just hard coded that address into the test, updating the one account but then creating no more accounts. But for the first run I use keypair generate to get an address and then use the pubkey as the PDA (I have read this is less than optimal). I am getting an unknown signer error.

Here is the code.

#[derive(Accounts)]pub struct AccountStruct<'info> {    #[account(init, payer=authority, space = 50)]    pub storage_account: Account<'info, GameState>,    #[account(mut)]    pub authority: Signer<'info>,    pub system_program: Program<'info, System>,}#[account]pub struct GameState {    pub time_of_last_update: i64,    pub current_state: i8,     pub wheel_speed: i8,     pub authority: Pubkey,}#[derive(Accounts)]pub struct UpdateValues<'info> {    |   #[account(mut, has_one = authority)]    |   pub storage_account: Account<'info, GameState>,    |   pub authority : Signer<'info>,    |   //authority: Pubkey,}#[program]pub mod looptest {    use super::*;    pub fn initialize (ctx: Context<AccountStruct>) -> Result<()> {    |   Ok(())    }   

And the TS:

const provider = anchor.AnchorProvider.env();  anchor.setProvider(provider);  const program = anchor.workspace.Looptest as Program<Looptest>;  const storageAccount = anchor.web3.Keypair.generate();   //const storageAccount = new anchor.web3.PublicKey('');   it("Is Initialized", async () => {        await program.methods.initialize()            .accounts({                storageAccount: storageAccount.publickey,                authority: provider.wallet.publicKey,                systemProgram: anchor.web3.SystemProgram.programId,            }).            signers([storageAccount])            .rpc()            });            //console.log("Transaction Signature -> ", tx);        console.log("Storage Account Public Key -> ", storageAccount.publickey);        

Why am I getting the following test error?

    1. looptestIs Initialized:Error: unknown signer: B8g4amuQepUBrn542kgxH6B6utwgv47oZZ348bYU8T7Jat Transaction._addSignature (node_modules/@solana/web3.js/src/transaction/legacy.ts:722:13)at forEach (node_modules/@solana/web3.js/src/transaction/legacy.ts:698:12)at Array.forEach ()at Transaction._partialSign (node_modules/@solana/web3.js/src/transaction/legacy.ts:696:13)at Transaction.partialSign (node_modules/@solana/web3.js/src/transaction/legacy.ts:688:10)at /home/infinity/looptest/node_modules/@project-serum/anchor/src/provider.ts:143:10at Array.forEach ()at AnchorProvider.sendAndConfirm (node_modules/@project-serum/anchor/src/provider.ts:142:21)at processTicksAndRejections (node:internal/process/task_queues:95:5)at MethodsBuilder.rpc [as _rpcFn] (node_modules/@project-serum/anchor/src/program/namespace/rpc.ts:29:16)

Viewing all articles
Browse latest Browse all 8156

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>