useHasChainPermission
useHasChainPermission Hook¶
The useHasChainPermission hook lets you check whether a given blockchain address has the necessary permission by reading the on-chain state.
import React from "react";
import { useHasChainPermission } from "@redbellynetwork/eligibility-sdk";
const PermissionStatus: React.FC<{ userAddress: string }> = ({
userAddress,
}) => {
const { data, error, isLoading, refetch } =
useHasChainPermission(userAddress);
if (isLoading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>;
return (
<div>
{data ? (
<p>User {userAddress} is allowed.</p>
) : (
<p>User {userAddress} is not allowed.</p>
)}
</div>
);
};
export default PermissionStatus;
Parameters¶
address
The blockchain address to check for permission.
Return Value¶
The hook returns the object provided by useReadContract
, which includes:
-
data
The response from the contract call. Typically, this is a boolean indicating if the address is allowed. -
isLoading
A boolean that is true while the contract call is in progress. -
error
An error object if the call fails; otherwise, undefined. -
refetch
A function to manually trigger a re-fetch of the contract state.