I'm trying to use the OpenSea SDK along with the ethers library in my JavaScript code. However, when I run the code, I encounter a TypeError: Cannot read properties of undefined (reading 'from') related to ethers.
const sdk = require("api")("@opensea/v2.0#xx4df2gljerlft1");
const { ethers } = require("ethers");
sdk.auth("---redacted---");
sdk.retrieveAllListings({ limit: "1", slug: "owlpha" })
.then(({ data }) => {
const price = data.listings[0].price;
console.log(price);
const value = price.current.value;
console.log(value);
const result = ethers.BigNumber.from(value);
const numberString = ethers.utils.formatEther(result);
console.log(numberString);
})
.catch((err) => console.error(err));
I have the ethers library installed with version 6.6.2. However, it seems that the ethers object is undefined, resulting in the error. Could you please help me understand why I'm encountering this error and how to resolve it?