Skip to main content

useRoleMembers

Hook for getting all wallet addresses that have a specific role in a smart contract.

Available to use on contracts that implement the PermissionsEnumerable interface.

import { useRoleMembers } from "@thirdweb-dev/react";

const { data, isLoading, error } = useRoleMembers(contract, "{{role_name}}");

Usage

Provide your contract instance from the useContract and role name as the arguments.

import { useContract, useRoleMembers } from "@thirdweb-dev/react";

// Your smart contract address (must implement permission controls)
const contractAddress = "{{contract_address}}";

const roleName = "admin";

function App() {
const { contract } = useContract(contractAddress);
const { data, isLoading, error } = useRoleMembers(contract, roleName);
}

Configuration

roleName

roleName

The name of the role to get the members of. Can be any custom role, or a built-in role, such as admin, transfer, minter, pauser, lister, asset, unwrap, or factory.

import { useContract, useRoleMembers } from "@thirdweb-dev/react";

// Your smart contract address (must implement permission controls)
const contractAddress = "{{contract_address}}";

const roleName = "admin";

function App() {
const { contract } = useContract(contractAddress);
const { data, isLoading, error } = useRoleMembers(
contract,
roleName,
);
}

Return Value

Return Value

The hook's data property, once loaded, is an array of wallet addresses that have the specified role.

string[] | undefined