metaplex-foundation / metaplex

A directory of what the Metaplex Foundation works on!
https://metaplex.com
Apache License 2.0
3.32k stars 6.25k forks source link

Error: Invalid option tokenMint #2291

Open tadeoaguilar opened 1 year ago

tadeoaguilar commented 1 year ago

I have an error when using project-serum/anchor library to fetch the status of a Candy Machine. It throws:

Unhandled Runtime Error Error: Invalid option tokenMint

My code is the following:

` const provider = getProvider();

    // Get metadata about your deployed candy machine program
    const idl = await Program.fetchIdl(candyMachineProgram, provider);

    // Create a program that you can call
    const program = new Program(idl, candyMachineProgram, provider);

    // Fetch the metadata from your candy machine
   **//This is the line of code that is failing**
    const candyMachine = await program.account.candyMachine.fetch(
        "A8N1TGFxC3eesH4vtQuLiCMHdBDZNuVJM925q5xhN71z"
    );

`

Please, any help with this issue will be highly appreciated.

JeffKGabriel commented 1 year ago

Yes for me as well- Error: Invalid option tokenMint

i am using candy-machine-ui , npm i, create .env, and insert my REACT_APP_CANDY_MACHINE_ID=***

I wonder if it has todo with candy-machine-ui using "@project-serum/anchor": "^0.17.0", dependency - im not sure

in candy-machine-ui it looks like it is happening at getCandyMachineState , Home.tsx line: 99 -> which calls candy-machine.ts and im seeing issues resolving const state: any = await program.account.candyMachine.fetch(candyMachineId);

program.account.candyMachine looks like it has the following attributes from logs

_coder:
_idlAccount:
_programId:
_provider:
_size:
coder: (...)
programId:(...)
provider:(...)
size:(...)

but getProgramState() doesnt seem to get past this line await program.account.candyMachine.fetch(

tadeoaguilar commented 1 year ago

I tried changing the anchor version to other stable releases but no luck at all. I found that Metaplex has recently updated the documentation. There are new ways to connect with the Cany Machine, I will try and update here. https://docs.metaplex.com/programs/candy-machine/how-to-guides/my-first-candy-machine-part2

tadeoaguilar commented 1 year ago

Haha, some progress with the new Metaplex guide. I have a different error now.

:82 Uncaught (in promise) TypeError: (0 , _types_BigNumber_mjs__WEBPACK_IMPORTED_MODULE_3__.toBigNumber)(...).toBuffer is not a function at toCandyMachine (CandyMachine.mjs:82:54) at Object.handle (findCandyMachineByAddress.mjs:59:40) at async Disposable.run (Disposable.mjs:22:1) toCandyMachine @ CandyMachine.m

image

tanlethanh commented 1 year ago

For those who still find the answer, the problem is using the incorrect program id (candy machine v1, v2, or v3) for the account. You can search at https://explorer.solana.com/ by your CANDY_MACHINE_ID and find assigned program id, the actual program id that suits your candy machine version. Then set the id to candyMachineProgram in above snippet