Hello, I’ve been dealing with this issue for a while. I’m using the React boilerplate and can’t get the chainId of the current chain of the user ( I am currently on ETH Ropsten testnet).
import { useEffect, useState } from "react";
import { Select } from 'antd';
import { useMoralis } from "react-moralis";
import { getCollectionsByChain } from 'helpers/collections';
const SearchCollections = () => {
const { Option } = Select;
const { isWeb3Enabled, enableWeb3, chainId } = useMoralis();
const [NFTCollections, setNFTCollections] = useState("")
// const NFTCollections = getCollectionsByChain(chainId);
useEffect(() => {
const chain = getCollectionsByChain(chainId);
const fetchData = () => {
setNFTCollections(chain)
}
fetchData()
if (!isWeb3Enabled) {
enableWeb3();
}
}, [isWeb3Enabled]);
return (
<>
<Select
showSearch
style={{
width: "1000px",
marginLeft: "20px"
}}
placeholder="find a collection"
optionFilterProp="children"
>
{NFTCollections &&
NFTCollections.map((collection, i) =>
<Option value={collection.addrs} keys={i}>{collection.name}</Option>)}
</Select>
</>
)
}
export default SearchCollections;