1
async function createCounter() {
    const provider = getProvider();

    if (!provider) {
        console.error('Provider is not available');
        return;
    } 
    if (!baseAccount || !baseAccount.publicKey) {
        console.log('Error: baseAccount or publicKey is missing.');
        return;
    }

    if (!web3.SystemProgram.programId) {
        console.log('Error: SystemProgram programId is missing.');
        return;
    }
    // Get the connected Phantom wallet's public key
    const connectedPublicKey = provider.wallet.publicKey;
    const contract = JSON.stringify(idl);
    const instance = JSON.parse(contract);
    const program = new Program(instance, idl.metadata.address, provider);
    try {
        console.log("baseAccount",baseAccount)
        console.log(baseAccount.publicKey)
        const init = await program.rpc.initialize(1, {
            accounts: {
                authority: provider.wallet.publicKey,
                pool: baseAccount.publicKey,
                vault: baseAccount.publicKey,
                owner: provider.wallet.publicKey,
                poolSigner: connectedPublicKey,
                systemProgram: web3.SystemProgram.programId,
            },
            signers: [baseAccount],
        });

        console.log('Pool Initialized:', init);
        const account = await program.account.myAccount.fetch(baseAccount.publicKey);
        console.log('account: ', account);
    }
    catch (err) {
        console.log("Transaction error: ", err);
    }
}

Transaction error: Error: unknown signer: 149J5z7P1MLvbUMepVf2DCxESoRPN5cQHFdA7dwCW121

facing this issue while initilize smart contract

Here is my account struct

[derive(Accounts)]
#[instruction(nonce: u8)]
pub struct Initialize<'info> {
    /// CHECK
    pub authority: UncheckedAccount<'info>,
    owner: Signer<'info>,
    #[account(
        seeds = [
            pool.to_account_info().key.as_ref(),
        ],
        bump = nonce,
    )]
    /// CHECK
    pool_signer: UncheckedAccount<'info>,
    #[account(mut)]
    /// CHECK
    pool: Box<Account<'info, Pool>>,
    #[account(
        mut,
        seeds = [
            pool.to_account_info().key.as_ref(),
        ],
        bump = nonce,
    )]
    /// CHECK
    vault: AccountInfo<'info>,
    system_program: Program<'info, System>,
}

1 Answer 1

1

In your accounts struct the only expected signer is owner: owner: Signer<'info>

When you call this you pass the connected wallet as the owner: owner: provider.wallet.publicKey

But then you pass a different account called baseWallet as the signer: signers: [baseAccount]. You're passing that as the pool and vault, neither of which are signers on the instruction. This baseWallet is probably 149J5z7P1MLvbUMepVf2DCxESoRPN5cQHFdA7dwCW121.

You should be able to pass provider.wallet as the signer instead, which is the account expected to sign the transaction.

3
  • 1
    Thanks. It worked!
    – user9345
    Commented Feb 20 at 15:56
  • Getting this issue now: Transaction error: Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x92 at Connection.sendEncodedTransaction (connection.ts:5921:1) at async Connection.sendRawTransaction (connection.ts:5880:1) at async sendAndConfirmRawTransaction (send-and-confirm-raw-transaction.ts:84:1) at async w.send (provider.ts:124:1) at async Object.initialize (rpc.ts:26:1) at async createCounter (App.tsx:111:1)
    – user9345
    Commented Feb 20 at 17:10
  • Please create a separate question if you're having a separate issue
    – Jon C
    Commented Feb 26 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.