πͺToken Gating (Ethereum / EVM)
A guide to start token gating anything in minutes.
Requirements
βοΈStart Here: SetupToken Gate Anything
Login User w/ Token Ownership Requirements
import Picket from "@picketapi/picket-js";
const picket = new Picket('YOUR_PUBLISHABLE_KEY_HERE');
// These requirements are for the Ethereum Mainnet
// See Token Ownership Requirements section below for examples of
// requirements other supported chain.
const requirements = {
// optional. The default chain is the Ethereum Mainnet
chain: "ethereum",
// Replace this example address with whichever contract you are verifying ownership for
contractAddress: '0x8a90cab2b38dba80c64b7734e58ee1db38b8992e',
// Replace with minimum balance you want to verify users' currently hold,
// or omit if any number of tokens is sufficient
minTokenBalance: 1
}
const { accessToken, user } = await picket.login(requirements);
console.log(user);import { PicketProvider, usePicket } from "@picketapi/picket-react";
function MyApp({ children }) {
return (
<PicketProvider apiKey="YOUR_PUBLISHABLE_KEY_HERE">
{children}
</PicketProvider>
);
}
const requirements = {
// optional. The default chain is the Ethereum Mainnet
chain: "ethereum",
// Replace this example address with whichever contract you are verifying ownership for
contractAddress: '0x8a90cab2b38dba80c64b7734e58ee1db38b8992e',
// Replace with minimum balance you want to verify users' currently hold,
// or omit if any number of tokens is sufficient
minTokenBalance: 1
}
function MySecurePage() {
const {
isAuthenticating,
isAuthenticated,
authState,
logout,
login
} = usePicket();
// user is logging in
if (isAuthenticating) return "Loading";
// user is not logged in
if (!isAuthenticated) {
return (
<div>
<p>You are not logged in!</p>
<button onClick={() => login(requirements)}>Login with Wallet</button>
</div>
)
}
// user is logged in π
const { user } = authState;
const { walletAddress } = user;
return (
<div>
<p>You are logged in as {walletAddress} </p>
<button onClick={() => logout()}>Logout</button>
</div>
)
}Token Ownership Requirements
Using Access Tokens
πWorking with Access TokensLast updated