Is it possible, in Web3, to call a function which would require the user to first hold an ERC20 token before an image/text is visible? This would be similar to a password requirement, but instead of typing a password for the function to take effect, they would simply have to hold at least 1 ERC20 token. Now, in solidity I've been able to write a function that simply returns a text line if msg.sender has at least one ERC20. I want to do this but in web3 that would reveal a .jpg image of instructions:
function Reveal()override public view returns (string memory) {
require(ERC20Token(0xB0Bd09D....).balanceOf(msg.sender) >= 1 wei, "Error");
return 'Thank you for collecting an ERC20Token, the instructions will be sent out shortly';
}
On a website I have a .jpg image that has instructions written on it for the msg.sender, but only want them to have this image visible to viewers that hold a token. I have a button labeled "Reveal" with an OnClick that would fire something like this:
//sender presses "reveal" button, function checks if sender has at least 1 ERC20Token. If true, then "Instructions" image is made visible. If not, textbox appears.
contract.methods.reveal.call()({
if(ERC20Token(0xB0Bd09D....).balanceOf(msg.sender) >= 1 wei); {
document.getElementById("instructions").style.visibility="visible";
} else{
//Tell viewer that they require ERC20 token
buttonx.innerHTML = " You require at least 1 ERC20Token to proceed";
I'm probably going about this wrong in Solidity, but trying to figure it out. So far I've been using Metamask and selecting the current users account with window.web3.currentProvider.selectedAddress
which I should incorporate as well?