metaplex-foundation / js-deprecated

Deprecated Metaplex JavaScript SDK
https://metaplex-foundation.github.io/js/
MIT License
128 stars 77 forks source link

initStore is not compatible with solana wallet adapter #182

Closed littleV closed 2 years ago

littleV commented 2 years ago

Describe the bug initStore is not using the wallet.publicKey properly when setting the admin using new PublicKey() from web3.js

To Reproduce Use the following code in a next.js project

import * as solanaWeb3 from "@solana/web3.js";
import { WalletMultiButton } from "@solana/wallet-adapter-react-ui";
import { WalletNotConnectedError } from "@solana/wallet-adapter-base";
import { useConnection, useWallet } from "@solana/wallet-adapter-react";
import React, { FC, useCallback, useEffect } from "react";
import { Connection, programs, actions } from "@metaplex/js";
const {
  metadata: { Metadata },
} = programs;

export default function Home() {
  const connection = new Connection("devnet");
  const { wallet } = useWallet();
  useEffect(async () => {
    try {
      const { storeId } = await actions.initStore({
        connection,
        wallet,
      });
      console.log(storeId);
    } catch (error) {
      console.log(error);
    }
  }, [wallet]);
  return (
    <div className={styles.container}>
      <WalletMultiButton />
    </div>
  );
}

It logs an error "TypeError: Cannot read properties of undefined (reading '_bn')" because of this line :in initStore.tx

Expected behavior It should support solana wallet since it's using the same PublicKey from solana web3.js

Fix use new PublicKey(wallet.publicKey.toBase58()) or just pass in wallet.publicKey

littleV commented 2 years ago

Nvm, I figured it out that I was not passing the wallet to initStore properly.