1

I have a very weird use case.

I have a method in a program, my method is call "bid"

When i try to call it with program.transaction.bid(...) it worked 2 times, and it's not working anymore, i get the error above.

I haven't changed anything in the meantime. Nor the IDL, nor the deployed program.

I'm 100% sure that the loaded IDL is okay (i checked it with a console.log of program)

I'm aware that this error usually comes from misspelled instruction names, or case, but here it should not be the case since it worked, and it's not working anymore with no updates linked to this.

is there a way to try to understand the error thru logging stuff ? (try to see how anchor encode the instruction for example, check discriminator, etc ?)

May be someone have experienced the same problem ?

thanks in advance !

Edit after @0xShuk answer :

I have a method like this in the IDL :

{
  "name": "bid",
  "accounts": [
    {
      "name": "mint",
      "isMut": false,
      "isSigner": false
    },
    {
      "name": "buyer",
      "isMut": true,
      "isSigner": true,
      "docs": [
        "CHECK"
      ]
    },
    {
      "name": "seller",
      "isMut": true,
      "isSigner": false,
      "docs": [
        "CHECK"
      ]
    },
    {
      "name": "escrowAccount",
      "isMut": true,
      "isSigner": false,
      "docs": [
        "CHECK"
      ]
    },
    {
      "name": "vaultAuthority",
      "isMut": false,
      "isSigner": false,
      "docs": [
        "CHECK"
      ]
    },
    {
      "name": "vaultAccount",
      "isMut": true,
      "isSigner": false,
      "docs": [
        "CHECK"
      ]
    },
    {
      "name": "escrowAccountAuction",
      "isMut": true,
      "isSigner": false,
      "docs": [
        "CHECK"
      ]
    },
    {
      "name": "chainlinkFeed",
      "isMut": false,
      "isSigner": false
    },
    {
      "name": "chainlinkProgram",
      "isMut": false,
      "isSigner": false
    },
    {
      "name": "systemProgram",
      "isMut": false,
      "isSigner": false,
      "docs": [
        "CHECK"
      ]
    },
    {
      "name": "rent",
      "isMut": false,
      "isSigner": false
    },
    {
      "name": "tokenProgram",
      "isMut": false,
      "isSigner": false,
      "docs": [
        "CHECK"
      ]
    }
  ],
  "args": [
    {
      "name": "price",
      "type": "u64"
    },
    {
      "name": "numberRandomForSeeds",
      "type": "u8"
    }
  ]
},

and the client side code looks like this :

var transaction = await program.value.transaction.bid(
new BN(bidAmount),
number_random_for_seeds,

{
  accounts: {
    mint: mintAddress,
    buyer: buyer,
    seller: seller,
    escrowAccount: escrowAccountBid.publicKey,
    escrowAccountAuction: escrowAccountAuction,
    vaultAuthority: vaultAccountAuthority,
    vaultAccount: vaultAccountPda,
    chainlinkFeed: CHAINLINK_FEED,
    chainlinkProgram: CHAINLINK_PROGRAM,
    systemProgram: SystemProgram.programId,
    rent: SYSVAR_RENT_PUBKEY,
    tokenProgram: TOKEN_PROGRAM_ID
  },
  instructions: [
    await program.value.account.escrowAccountAuctionBid.createInstruction(escrowAccountBid)
  ]
}

)

for information, i use program.value because i'm in a vue3 reactive env, and the program.value variable is equal to "program" that we usually use with anchor.

Edit after some more reasearch

There is something even more weird :

i have this code :

    let preimage = 'global:bid';

let result = Buffer.from(sha256.digest(preimage)).slice(0, 8);

const toHexString = (bytes) => {
  return Array.from(bytes, (byte) => {
    return ('0' + (byte & 0xff).toString(16)).slice(-2);
  }).join('');
};

console.log(toHexString(result));

in my app (vue + vite app) this logs "27719e5294ef89c7" which is the wrong discriminator, and in another app (node app) this logs "c738552692f3259e" which is the right discriminator.
In other words, the discriminator creation in my app is broken for some reason. Could it be linked with this line in my code ?

var global = global || window;

Seems like there is something breaking "sha256" code...

5
  • if this may help, here is a link to solscan to a failed transaction : solscan.io/tx/…
    – Effe2
    Commented Aug 29, 2023 at 17:56
  • 1
    The discriminator in the failed transaction is incorrect. If the instruction name is bid, the discriminator should be c738552692f3259e like this tx: solscan.io/tx/…. The problem is most probably either in the client side code or in IDL, share both in the question for further look.
    – 0xShuk
    Commented Aug 29, 2023 at 19:05
  • thanks for your reply. I have edited the question. How do you "compute" the descriminator ? do you know where it is computed in anchor's code ? i don't get wht it worked, and now it's not working anymore with no updates linked to this...
    – Effe2
    Commented Aug 30, 2023 at 16:49
  • Could it be linked to github.com/coral-xyz/anchor/issues/2371 ? i'm using vite as well. Doesn't work locally neither tho (or it worked, but it's not working anymore for an unknown reason)
    – Effe2
    Commented Aug 30, 2023 at 19:44
  • i'm getting closer i think, please see my last edit about sha256 potentially broken
    – Effe2
    Commented Aug 30, 2023 at 20:41

1 Answer 1

1

the solution is here : https://github.com/coral-xyz/anchor/issues/2619

just need to update anchor :)

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.