AudiusProject/fetch-nft

`fetchClient.getSolanaCollectibles()` results in error: Module not found: Can't resolve 'encoding' in '/Users/USER/Desktop/audius-nft/audius-nft/node_modules/node-fetch/lib'

tesla809 opened this issue · 0 comments

Describe the bug

fetchClient.getSolanaCollectibles() as described in the docs does not work and results in the error

error: Module not found: Can't resolve 'encoding' in '/Users/USER/Desktop/audius-nft/audius-nft/node_modules/node-fetch/lib'

Instead, had to use fetchClient.getSolanaCollectibles(["ADDRESS"]).

To Reproduce

see below code:
src/app/page.tsx

import React, { useEffect, useState } from "react";
import Image from "next/image";

import { FetchNFTClient } from "@audius/fetch-nft";

import NFT from "./NFT";

// FETCH test data
async function getPuppers() {
  const response = await fetch("https://dog.ceo/api/breeds/image/random", {
    cache: "no-cache",
  });
  const data = await response.json();
  return data;
}

// NFT
// upon checking Opensea the address: GrWNH9qfwrvoCEoTm65hmnSh4z3CD96SfhtfQY6ZKUfY
// doesn't yield anything.
// Where is this data being pulled from?
async function getSolanaCollectibles() {
  // Initialize fetch client
  const fetchClient = new FetchNFTClient();

  // // Fetching Solana collectibles for the given wallets
  return fetchClient
    .getSolanaCollectibles(["GrWNH9qfwrvoCEoTm65hmnSh4z3CD96SfhtfQY6ZKUfY"])
    .then(({ res }) => {
      return res;
    });

  // return fetchClient
  //   .getCollectibles({
  //     solWallets: ["GrWNH9qfwrvoCEoTm65hmnSh4z3CD96SfhtfQY6ZKUfY"],
  //   })
  //   .then((res) => {
  //     return res;
  //   });
}

// TESTING OUT OPENSEA API since Fetch-API is causing issues for setup
async function getEthereumCollectibles() {
  const sdk = require("api")("@opensea/v2.0#1nqh2zlnvr1o4h");
  sdk.auth("04c8ae776ac44b4cabebbed161dfbc8c");
  sdk.server("https://api.opensea.io");
  return await sdk
    .list_nfts_by_account({
      chain: "ethereum",
      address: "0x5A8443f456f490dceeAD0922B0Cc89AFd598cec9",
    })
    .then(({ data }) => {
      return data;
    })
    .catch((err) => console.error(err));
}

export default async function Home() {
  const dogs = await getPuppers();
  console.log(dogs);

  let solAssets;
  const getSolData = await getSolanaCollectibles().then((res) => {
    // pluck out the Solana NFT data
    solAssets = res; // get base object
    console.log("WORKING DATA:", solAssets);
  });

  solAssets =
    solAssets.solCollectibles["GrWNH9qfwrvoCEoTm65hmnSh4z3CD96SfhtfQY6ZKUfY"];

  console.log("??????????:", solAssets);

  let ethAssets;
  const getEthData = await getEthereumCollectibles().then((res) => {
    ethAssets = res; // get base object
    console.log("WORKING DATA:", ethAssets);
    console.log("DATA 1:", ethAssets.nfts);
  });

  return (
    <div>
      <h1>Audius Data</h1>
      <h2>Ethereum Collectables</h2>
      <NFT data={ethAssets.nfts} />

      <h2>Solana Collectables</h2>
      <NFT data={solAssets} />

      <h1>Doggos Data</h1>
      <Image
        src={dogs.message}
        width={500}
        height={500}
        alt="doggos"
        priority
      />
    </div>
  );
}

Expected behavior

Expected to see Solana data upon running npm run dev. by using the fetchClient.getSolanaCollectibles()

Your environment

Dev Environment

package.json

{
  "name": "audius-nft",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@audius/fetch-nft": "^0.1.8",
    "@solana/spl-token": "^0.1.8",
    "@solana/web3.js": "^1.87.2",
    "api": "^6.1.1",
    "module-alias": "^2.2.3",
    "next": "13.5.6",
    "react": "^18",
    "react-dom": "^18"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "autoprefixer": "^10",
    "eslint": "^8",
    "eslint-config-next": "13.5.6",
    "postcss": "^8",
    "tailwindcss": "^3",
    "typescript": "^5"
  }
}

OS

OS: MacOS 13.4 - Ventura
NextJS: 13
Node version: V20.5.0
Npm version: 9.8.1
Browser name and version: Chrome 118.0.5993.70

Additional context: