Skip to main content

Achievo Frontend NFT Gating Documentation ( coming soon )

Overview

To log in to Achievo, the frontend connection requires a specific token ID minted for the user's address, along with a signature and a message signed by the user for Achievo authentication.

Authentication Process

1. Wallet Signature Generation

Using Viem, generate a signature from the user's wallet:

const ACHIEVO_MESSAGE = "ACHIEVO LOGIN";
const walletSignature = await walletClient?.signMessage({
account: walletClient?.account.address,
message: ACHIEVO_MESSAGE,
});

2. JWT Generation

With React v18 and Viem, call the endpoint to generate the JWT (JSON Web Token):

const { data: jwt } = await axios.post(
`${ACHIEVO_BASE_URL}/v1/auth/login/nftGating`,
{
tokenId: NFT_GATING_TOKEN_ID, // Provided by the Achievo team
address: walletClient?.account.address,
signature: walletSignature,
smartContractAddress: SMART_CONTRACT_ADDRESS, // Provided by the Achievo team
tenantId: TENANT_ID, // Provided by the Achievo team
message: walletMessage,
}
);
return { jwt };

3. Fetching NFT-Gating Data

The following JavaScript example demonstrates how to fetch nft gating data using Axios:

const checkNFTGating = async () => {
const {
data: { results },
} = await axios.post(
`${ACHIEVO_BASE_URL}/v1/crosschain/nftGating`,
{
smartContract: "0xD07180c423F9B8CF84012aA28cC174F3c433EE29",
chainId: 324, // only EVMs supported
erc: "721", // 1155, 20, 6551
checks: [
{
args: ["0xa0FDB2F6cf2Bf189db73B294A60088feF751bfCD"],
functionName: "balanceOf",
matchResult: 1,
matchOperation: "GREATER_THAN_OR_EQUAL", // EQUAL | GREATHER_THAN | LESS_THAN | GREATHER_THAN_OR_EQUAL | LESS_THAN_OR_EQUAL | NOT_EQUAL
},
{
args: [25],
functionName: "tokenURI",
matchResult: "x/ipfs/Qmc7c9tNVaaAbTM5RMgdPY7MjPoLDFfPw8BAv3WuBUrebe",
matchOperation: "EQUAL",
},
],
},
{
headers: { Authorization: jwt },
}
);
return { results };
};

Summary

To use Achievo's services in the front-end:

  1. Utilize the API key provided by Achievo for authentication.
  2. Ensure that any private keys or sensitive information are never exposed or sent to the front-end.
  3. The provided example demonstrates how to make an API call to retrieve nft gating data securely.
  4. This documentation provides the essential steps for front-end developers to securely integrate with Achievo's services.

Request schema:

This is the Zod schema to use as request:

  z.object({
body: z.object({
smartContract: z.string(),
chainId: z.number(),
erc: z.enum([ERCS.ERC20, ERCS.ERC721, ERCS.ERC1155, ERCS.ERC6551]),
checks: z.array(
z.object({
args: z.array(z.any()).optional(),
userAddress: z.string().optional(),
index: z.number().optional(),
functionName: z.enum([
DEFAULT_FUNCTIONS.balanceOf,
DEFAULT_FUNCTIONS.uri,
DEFAULT_FUNCTIONS.tokenURI,
]),
matchResult: z.string().or(z.number()),
matchOperation: z.enum([
OPERATIONS.EQUAL,
OPERATIONS.GREATER_THAN,
OPERATIONS.LESS_THAN,
OPERATIONS.GREATER_THAN_OR_EQUAL,
OPERATIONS.LESS_THAN_OR_EQUAL,
OPERATIONS.NOT_EQUAL,
]),
})
),
}),
})
headers: HeaderJWT,

Supported operations:

export enum OPERATIONS {
EQUAL = 'EQUAL',
GREATER_THAN = 'GREATER_THAN',
LESS_THAN = 'LESS_THAN',
GREATER_THAN_OR_EQUAL = 'GREATER_THAN_OR_EQUAL',
LESS_THAN_OR_EQUAL = 'LESS_THAN_OR_EQUAL',
NOT_EQUAL = 'NOT_EQUAL',
}

supported functions:

export enum DEFAULT_FUNCTIONS {
balanceOf = 'balanceOf',
uri = 'uri',
tokenURI = 'tokenURI',
}

supported ERCS:

export enum ERCS {
ERC20 = '20',
ERC721 = '721',
ERC1155 = '1155',
ERC6551 = '6551',
}