I’m having trouble getting NFT data to show up in my React project. I followed a tutorial but keep getting an error that says programs.metadata.Metadata is undefined. The code seems simple enough but something isn’t working right.
import { Connection, programs } from '@metaplex/js';
const solanaConnection = new Connection('devnet');
const nftTokenId = 'Gz3vYbpsB2agTsAwedtvtTkQ1CG9vsioqLW3r9ecNpvZ';
const fetchNftData = async () => {
try {
const nftMetadata = await programs.metadata.Metadata.load(solanaConnection, nftTokenId);
console.log(nftMetadata);
} catch(err) {
console.log('Could not load NFT data');
console.log(err);
}
};
function MyApp() {
return (
<div className="container">
<button onClick={fetchNftData}>Load NFT Info</button>
</div>
);
}
export default MyApp;
The error message says “Cannot read properties of undefined (reading ‘Metadata’)”. I tried running this outside of React too and got the same problem. Has anyone run into this before? Maybe the library changed or I’m missing something obvious?