Calling an anchor (solana) program through classic javascript ? custom program error: 0x64

i deployed a program on the devnet, when i run anchor test, everything runs fine. The program needs 3 keys, and just return ok() (i commented everything inside).

I am trying to call this program in my single page app (with a phantom signature), but i got the following error: custom program error: 0x64

I think the problem is quite simple, but i can't get the reason.

const instructions: TransactionInstruction[] = [];  

const exchangeInstruction = new TransactionInstruction({

    programId: program_id,
    data: Buffer.alloc(0),
    keys: [

        { pubkey: publicKey1, isSigner: true, isWritable: true },

        { pubkey: publicKey2, isSigner: false, isWritable: true },

        { pubkey: system_program, isSigner: false, isWritable: false },

    ],
});

instructions.push(exchangeInstruction);

const transaction = new Transaction().add(...instructions);

transaction.feePayer = publicKey1;
transaction.recentBlockhash = (await connection.getRecentBlockhash()).blockhash;

var signedTransaction = await window.solana.signTransaction(transaction);

var signature = await connection.sendRawTransaction(signedTransaction.serialize());

The public key are from new PublicKey(...)

The program_id is the public key of my program (PublicKey())

There is no args in my program (i tried to delete data: {...} but got the same error).

When i call the program with the .ts file and anchor test, everything works fine, here is the code :

const tx = await program.rpc.initialize(
{
  accounts: {
    publicKey1: xxxx.publicKey,
    publicKey2: yyyy.publicKey,
    
    systemProgram: anchor.web3.SystemProgram.programId,
  },

  signers: [xxxx]
});

I must be missing something somewhere, but can't figure out where, if someone can help, would be highly appreciated

Upvotes: 0

Views: 1857

Answers (1)

Jon C
Jon C

Reputation: 8472

According to the Anchor documentation, error code 0x64, which corresponds to 100 in decimal, is InstructionMissing, some 8-byte identifier must be provided for the number of your instruction.

To fix that, you probably need to declare the instruction data as:

data: Buffer.alloc(8),

Reference at https://docs.rs/anchor-lang/latest/src/anchor_lang/error.rs.html#19

Upvotes: 1

Related Questions