HomeLearnAbout YamsTwitterDiscord
top bottom
7. Token Gating
Written Feb 1 2024 2:30 PM
by YamsDev
One of the selling points of many NFT projects is exclusive access to online content. The question is, how do you make such content require a certain token to be seen? Let's dive in.

First things first, this way of doing it requires access to an SQL database and the ability to use PHP on your webpage. If you are in need of a recommendation for a service that offers this, I have a referral link to the service I use.

So, the way I've done it for this site's Learning pages is to load the content with PHP, but set it to display: none.

<?php
//this is what is hidden behind the gate
$str = "This is a test.";

$hidden = " style='display: none'";

//this creates a connect wallet button,
echo (
"<div id='connect'>
<button onclick='connectWalletHandler()'>
Connect Wallet
</button>
</div>"
);
//this adds the hidden content
echo (
"<div id='article' ".$hidden.">
".$str."
</div>"
);
?>


Next, we need a JS script that will check the users wallet for the required token/NFT. Create a file called ethers.php in a folder named src, and put in the following:



Problem? Questions? Get in touch:

© 2021 - 2023 Ben "YamsDev" Davies