Hi I am trying to get the NFTs a user owns, based on the contract address I provide. I tried using the docs and examples provided but I cant get anything to work. I have a simple project I created using the starter tutorial. I’m using visual studio and react. I commented out the other methods I tried getting to work -
import {
Button,
Container,
Box,
Heading,
Alert,
AlertIcon,
AlertTitle,
AlertDescription,
CloseButton
} from "@chakra-ui/react";
import { useMoralis } from 'react-moralis';
import { Moralis } from 'moralis';
//const options = { chain: 'rinkeby', token_address: '0x00...' };
//const polygonNFTs = async () =>{await Moralis.Web3API.account.getNFTsForContract(options)};
const options = { chain: 'eth', token_address: '0x00..'}
const nfts = async () =>{await Moralis.Web3API.getNFTsForContract(options)};
function App() {
const { authenticate, isAuthenticated, isAuthenticating, authError, logout, user } = useMoralis();
//const options = { chain: 'eth', token_address: '0x1b61748EEB5da53B5444D42ce8878712ea9aBe14' };
//const pixlaNFTs = async () =>{ await Moralis.Web3API.account.getNFTsForContract(options)};
//const { getNFTBalances, data, error } = useNFTBalances();
/*const NFTBalances = () => {
return (
<div>
{error && <>{JSON.stringify(error)}</>}
<Button onClick={() => getNFTBalances({ params: { chain: "eth" } })}>Refetch NFTBalances</Button>
<pre>{JSON.stringify(data, null, 2)}</pre>
</div>
);
};*/
if(isAuthenticated){
return <Container>
<Heading>Welcome, {user.attributes.username}. {nfts}</Heading>
<Button onClick={() => logout()}>Disconnect</Button>
</Container>
}
return <Container>dApp
{authError &&(
<Alert status='error'>
<AlertIcon />
<Box flex='1'>
<AlertTitle>Authentication has failed</AlertTitle>
<AlertDescription display='block'>
{authError.message}
</AlertDescription>
</Box>
<CloseButton position='absolute' right='8px' top='8px' />
</Alert>
)}
<Button isLoading={isAuthenticating} onClick={() => authenticate()}>Authenticate</Button>
</Container>;
}
export default App;
I need to return how many NFTs the user owns from a specific contract and get the tokenID. I need these variables to interact with my smart contract to allow free minting for those users.