0

I'm following this article as a practice.

ts-node packages/cli/src/candy-machine-cli.ts verify --env devnet --keypair "C:\Windows\System32\~\.config\solana\devnet.json"

While trying to verify candy machine, I ran into

TypeError: Cannot read properties of undefined (reading '_bn') at isPublicKeyData (C:\Users\my-userName\Source\Repos\metaplex\js\node_modules@solana\web3.js\src\publickey.ts:29:35) at new PublicKey (C:\Users\my-userName\Source\Repos\metaplex\js\node_modules@solana\web3.js\src\publickey.ts:45:9) at C:\Users\my-userName\Source\Repos\metaplex\js\packages\cli\src\candy-machine-cli.ts:326:27 at step (C:\Users\my-userName\Source\Repos\metaplex\js\packages\cli\src\candy-machine-cli.ts:64:23) at Object.next (C:\Users\my-userName\Source\Repos\metaplex\js\packages\cli\src\candy-machine-cli.ts:45:53) at fulfilled (C:\Users\my-userName\Source\Repos\metaplex\js\packages\cli\src\candy-machine-cli.ts:36:58) at processTicksAndRejections (node:internal/process/task_queues:96:5)

By a quick search on the internet, some people say I need to first create the candy machine. So I ran

ts-node packages/cli/src/candy-machine-cli.ts create_candy_machine --env devnet --keypair "C:\Windows\System32\~\.config\solana\devnet.json"

But it gave me the same error.

Appreciate any advice about how I may solve this.

Circle Hsiao
  • 1,497
  • 4
  • 22
  • 37

3 Answers3

1

While trying to resolve another issue, I found the problem has something to do with the ts-node version that I was using.

Problem solved after update with command below

npm i ts-node@latest
Circle Hsiao
  • 1,497
  • 4
  • 22
  • 37
1

You need to provide a public key for getNameAccountKey, e.g.

import { Connection, PublicKey } from '@solana/web3.js';
import { getHashedName, getNameAccountKey, NameRegistryState } from '@solana/spl-name-service';
...
class SomeClass {

  constructor(private readonly configService: ConfigService) {
    this.publicKey = new PublicKey(
      this.configService.get('SOLANA_NAME_SERVICE_PUBLIC_KEY'), // that public key taken from `.env` config file
    );
  }

  ...

  private async resolveSnsName(name: string, connection: Connection): Promise<string> {
    try {
      const parsedName = name.replace('.sol', '');
      const hashedName = await getHashedName(parsedName);
      const domainKey = await getNameAccountKey(hashedName, undefined, this.publicKey);
      const registry = await NameRegistryState.retrieve(connection, domainKey);
      return registry.owner.toBase58();
    } catch {
      return null;
    }
  }
}
kosiakMD
  • 923
  • 7
  • 22
1

For anyone who sees this from now on (at least until any other update makes this obsolete), you can also get this error simply because you're trying to create a Candy Machine v1, which I was told on the Metaplex discord won't work anymore.

Make sure you follow the steps for using v2 (as of the date I write this), as covered in the official docs here: https://docs.metaplex.com/candy-machine-v2/configuration. You'll simply use a different command for the v2 package.

Look over the docs to check to confirm you're ready, but as reassurance, if your assets are set up and ready to go, do start here on Step 2 configuration (you can create the config file anywhere as long as you paste the correct path to it once it's required), then go to Step 4.

Rhoi
  • 11
  • 1