After logging in with metamask, I want to authorize according to whether the user has the Nft I want in their wallet (or rather, we can say according to the contract address of the token I want). But I return if else in the code. If the balance is greater than 1, I want to authorize it. "window.parent.postMessage" is not coming.
Connect metamask
<button class="rounded shadow-md bg-white px-4 py-2 mx-2 leading-8" @click="connectMetamask">
<img src="./../assets/images/metamask.svg"
class="inline-block mr-2" width="24" height="24" alt="Metamask">
Connect Metamask
</button>
</template>
<script>
import Web3 from 'web3';
export default {
name: 'ConnectMetamask',
methods: {
async connectMetamask() {
if (typeof window.ethereum !== 'undefined') {
window.web3 = new Web3(window.ethereum);
window.ethereum.enable();
const Address = await window.ethereum.request({ method: 'eth_requestAccounts' });
this.$store.commit('address', Address);
} else {
console.error('MetaMask is not detected!');
}
},
},
};
</script>
Balance of(this code)
<template>
</template>
<script>
import Web3 from 'web3';
export default {
name: 'balanceOf',
methods: {
async balanceOf(){
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
const account = accounts[0];
const minABI = [
// balanceOf
{
constant: true,
inputs: [{ name: '_owner', type: 'address' }],
name: 'balanceOf',
outputs: [{ name: 'balance', type: 'uint256' }],
type: 'function',
},
];
const a = 1;
const contractAddress = '0x495f947276749ce646f68ac8c248420045cb7b5e';
const openseaContract = new Web3.eth.Contract(minABI, contractAddress);
const balanceOfAccount = await openseaContract.methods.balanceOf(contractAddress).call();
console.log(balanceOfAccount);
if (balanceOfAccount >= a) {
window.parent.postMessage('Welcome to Pro Version ');
} else {
window.parent.postMessage('You dont have Genesis Card');
}
},
},
};
</script>