// Import the Web3 library and the contract ABI
import Web3 from 'web3';
import { abi } from './abi.json';
// Define the contract address and the NFT ID
const contractAddress = '0xabcdefghijklm';
const nftId = 1;
// Initialize Web3 and get the user's wallet
const initWeb3 = async () => {
if (window.ethereum) {
try {
await window.ethereum.enable();
return new Web3(window.ethereum);
} catch (error) {
console.error(error);
}
} else if (window.web3) {
return new Web3(window.web3.currentProvider);
} else {
console.error("Please install MetaMask!");
}
};
// Check if the user's wallet contains the NFT
const checkNFT = async () => {
const web3 = await initWeb3();
// Get the contract instance using the contract address and ABI
const contract = new web3.eth.Contract(abi, contractAddress);
// Get the user's address
const accounts = await web3.eth.getAccounts();
const userAddress = accounts[0];
// Check if the user's wallet contains the NFT with the specified ID
const nftOwner = await contract.methods.ownerOf(nftId).call();
if (nftOwner.toLowerCase() === userAddress.toLowerCase()) {
console.log("Congratulations, your wallet contains the NFT with ID", nftId);
} else {
console.log("Sorry, your wallet does not contain the NFT with ID", nftId);
}
};
// Call the checkNFT function when the page is loaded
window.addEventListener('load', checkNFT);
Please be advised that Ghost Trader is NOT an investment but an opportunity that you can participate in. Like any other opportunity of this nature, it has its risks and value of your capital can fluctuate down as well as up. Ghost Trader is not a regulated entity.