I am running VisualStudio Code, Sanity Studio, and Thirdweb

When I inspect the element on localhost:3000, I am able to see the array of my imported tokens on Sanity, but NOT on Thirdweb.

Here is a snippet of my code:

const sdk = new ThirdwebSDK(
   new ethers.Wallet(
    process.env.NEXT_PUBLIC_METAMASK_KEY,
    ethers.getDefaultProvider('https://rinkeby_xyz),
    ),
  )

const Portfolio = () => {
  const[sanityTokens, setSanityTokens] = useState([])
  const[thirdWebTokens, setThirdWebTokens] = useState([])
    
  useEffect (() => {
      const getSanityAndThirdWebTokens = async () => {
       const coins = await fetch("https://xyz"
          )
          const sanityTokens = (await coins.json()).result
          setSanityTokens(sanityTokens)
        
          setThirdWebTokens(
            sanityTokens.map(token => sdk.getTokenModule(token.contractAddress))
          )
      }
      return getSanityAndThirdWebTokens()
    }, [])
console.log('Sanity', sanityTokens) 
console.log('Thirdweb', thirdWebTokens)

Error Message: Unhandled Runtime Error TypeError: sdk.getTokenModule is not a function

How do I get the ThirdWeb array to show up?

2

There are 2 answers

0
Samuel Offem On

A lot has changed with thirdwebSDK. getTokenModule is no longer a valid function as of this time, instead try sdk.getToken(token.contractAddress) in the part of the code where you have sdk.getTokenModule(token.contractAddress)

0
nachoiacovino On

On the latest versions of thirdweb SDK, this is how you initialize the SDK:

const sdk = ThirdwebSDK.fromPrivateKey(PRIVATE_KEY, "rinkeby")

With that being said, you are not referencing a PRIVATE_KEY, you have NEXT_PUBLIC_METAMASK_KEY, which you should never do, this would make it so your private key is exposed to the client and anyone visiting your page will get full access to your wallet and will be able to steal all your funds.

What you should do is instantiate the SDK with a read-only RPC, no need to pass a private key at all in this situation. You can instantiate the SDK like this:

const sdk = new ThirdwebSDK("rinkeby")

And again, getTokenModule is not a function, you need to import getToken and pass the contract address.

I hope that helps.