Token-Gate a video with Livepeer and Whal3s

Example ACL Integrating Whal3s

You can also use access control with Whal3s to give NFT holders exclusive access to the content. You just need the utility ID.

The utility ID is generated when setting access control rules using Whal3s. You can do this with a few clicks using the Whal3s App (app.whal3s.xyz [recommended]) or with the API.

The following rules can be set:

  • Eligible tokens (via smart contract address)
  • Eligible traits (metadata)
  • One-time views (or any other limited amount per token)
  • Maximum total views (first come first served until threshold is reached)

Here is what an example route function:

import {NextApiRequest, NextApiResponse} from "next";
const CryptoJS = require("crypto-js");

export default async function handler(
    req: NextApiRequest,
    res: NextApiResponse
) {
    try { 
        const {accessKey} = req.body;
        const walletAddress = CryptoJS.AES.decrypt(accessKey, process.env.ENCRYPTION_KEY).toString(CryptoJS.enc.Utf8);
        const utilityId = process.env.WHAL3S_UTILITY_ID;

        const response = await fetch(`https://app.whal3s.xyz/api/v0/nft-validation-utilities/${utilityId}/wallet/${walletAddress}`)
        res.status(response.status).send('')
    } catch (e) {
        res.status(500).send('')
    }
}

The above code shows an example of how to perform an access control check for a web service using the Whal3s API. When a POST request is received at the /verify-livepeer endpoint, the script then maps /decrypts the accessKey to the wallet of the user who is requesting that media and checks eligibility to access the content according to the rules set on the Whal3s platform.

If the user is not eligible, the response status code is set to 403 (Forbidden).

This code provides a simple example of how to perform an ACL check using the Whal3s API.

Example project

You can find an example integration here.