0

I'm getting this error

const key = signer.publicKey.toString();
                                   ^

TypeError: Cannot read properties of undefined (reading 'toString')
    at Transaction.partialSign (/home/Abhi/xode/sol/testServer/testServer2/node_modules/@solana/web3.js/lib/index.cjs.js:3045:36)
    at NodeWallet.signTransaction (/home/Abhi/xode/sol/testServer/testServer2/node_modules/@project-serum/anchor/dist/cjs/nodewallet.js:23:12)
    at AnchorProvider.sendAndConfirm (/home/Abhi/xode/sol/testServer/testServer2/node_modules/@project-serum/anchor/dist/cjs/provider.js:83:32)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async MethodsBuilder.rpc [as _rpcFn] (/home/Abhi/xode/sol/testServer/testServer2/node_modules/@project-serum/anchor/dist/cjs/program/namespace/rpc.js:15:24)
    at async file:///home/Abhi/xode/sol/testServer/testServer2/app.js:100:20

I'm trying to use this function

const freeze = await program.methods.freezeToken().accounts({
      sender : sender,
      senderAta : senderAta,
      mint : mint,
      vaultAccount : vaultAccount,
      freezingConfig : freezingConfig,
      tokenProgram : tokenProgram,
      systemProgram : systemProgram,
      rent : rent
    }
  ).signers(walletWrapper.payer).rpc()

For the program account

#[derive(Accounts)]
pub struct FreezeToken<'info> {
    ///CHECK : Not dangerous
   #[account(mut, signer)]
    pub sender: AccountInfo<'info>,
    #[account(mut)]
    pub sender_ata: Account<'info, TokenAccount>,

   pub mint: Account<'info, Mint>,
    #[account(
        init,
        seeds = 
        [   
            b"vault".as_ref(),
            mint.key().as_ref()
        ],
        bump,
        payer = sender,
        token::mint = mint,
        token::authority = sender,
    )]
    pub vault_account: Account<'info, TokenAccount>,   
      ///CHECK : Not dangerous

    #[account(
        init,
        seeds = 
        [   
            b"config".as_ref(),
            mint.key().as_ref()
        ],
        bump,
        payer = sender,
        space = 90
    )]
    pub freezing_config : Account<'info,FreezingConfig>,
    
    /// CHECK: This is not dangerous because we don't read or write from this account
    pub token_program: AccountInfo<'info>,
    pub system_program: Program<'info, System>,
    pub rent: Sysvar<'info, Rent>,
}

I feel i'm missing some parameters or arguments, but i can't figure it out.

The parameters i use are

const sender = new PublicKey("U4NHM8DNT3kCNrRtB9ymgt1mcR6RBaHwUHWLoxM4KTF");
  const senderAta = new PublicKey("2zfkpS8VNWk2t8B2737B6xxFVw8WFNjF3qWXvtQAbgK4");
  const mint = new PublicKey("9jcbX9YT6ZzvEsuUrfxcV8Chv3uz7TMmPo4MXXDc5UhV");
  const vaultAccount = new PublicKey("9UgS3GBfQVmsEMVje5tniYgYszDs5G7orcw8r71Mdesb");

  const freezingConfig = new PublicKey('FK81EDxxU7pPwm5BSs5oFQt5deoRxynuJwu8bnr4nbhf')
  const tokenProgram = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
  const systemProgram = new PublicKey('11111111111111111111111111111111');
  const rent = new PublicKey("SysvarRent111111111111111111111111111111111");
const walletWrapper =new anchor.Wallet(walletKeyPair);

1 Answer 1

1

Your account parameters should be the Public Key of the account, not the Keypair. For instance if you generate a new account using let newAccount = anchor.web3.generate() to pass into your instruction call, pass it in as newAccount: newAccount.PublicKey().

8
  • which parameter should i replace it with? Aug 1, 2022 at 19:10
  • All the accounts are public key type and correct as well, i double checked them Aug 1, 2022 at 19:21
  • In that case the issue is likely with your signer. That should be a Keypair instead of a PublicKey
    – Ademola
    Aug 1, 2022 at 19:26
  • tried passing passing keypair,wallet and pulickey but the same error Aug 1, 2022 at 19:28
  • 1
    Update the question to include a more complete code sample where you show the definition of all the parameters you use in the function call
    – Ademola
    Aug 1, 2022 at 19:41

Your Answer

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

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