ProjectOpenSea / opensea-js

TypeScript SDK for the OpenSea marketplace
https://docs.opensea.io/reference
MIT License
2.28k stars 958 forks source link

TypeError: Cannot read property 'HttpProvider' of undefined #55

Closed 0xtaosu closed 3 years ago

0xtaosu commented 3 years ago

Hey Guy! I run the demo of README and I paste it above ,

import * as Web3 from 'web3';
import { OpenSeaPort, Network } from 'opensea-js';

// This example provider won't let you make transactions, only read-only calls:
const provider = new Web3.providers.HttpProvider('https://mainnet.infura.io');

const seaport = new OpenSeaPort(provider, {
  networkName: Network.Main,  
});

const asset = {
  tokenAddress: "0x06012c8cf97bead5deae237070f9587f8e7a266d", // CryptoKitties
  tokenId: "1", // Token ID
}

const balance = await seaport.getAssetBalance({
  accountAddress, // string
  asset, // Asset
})

const ownsKitty = balance.greaterThan(0)
console.log(ownsKitty)

However, it print error message

const provider = new Web3.providers.HttpProvider('https://mainnet.infura.io');
                                    ^
TypeError: Cannot read property 'HttpProvider' of undefined

Also , there are some info which may help you,

Hope you can give me some advice and I ask same question on discord server

wizardengineer commented 2 years ago

What was the solution?

Brentably commented 2 years ago

Yeah what the solution