useRoleMembers
Hook for fetching the list of accounts with a given role in a smart contract.
import { useRoleMembers } from "@thirdweb-dev/react";
Usage
Provide your smart contract and role name as the arguments.
import { useRoleMembers, useContract, Web3Button } from "@thirdweb-dev/react";
// Your smart contract address
const contractAddress = "{{contract_address}}";
function App() {
const { contract } = useContract(contractAddress);
const { data: members, isLoading, error } = useRoleMembers(contract, "admin");
if (error) {
console.error("failed to fetch members", error);
}
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
// Do something with the members array
}
>
Get Members
</Web3Button>
);
}
Configuration
role
The role should correspond to one of the roles available in your smart contract.
For example, if your smart contract implements the Ownable
interface,
your role should be either owner
or admin
.
import { useRoleMembers, useContract, Web3Button } from "@thirdweb-dev/react";
// Your smart contract address
const contractAddress = "{{contract_address}}";
function App() {
const { contract } = useContract(contractAddress);
const { data: members, isLoading, error } = useRoleMembers(contract, "owner");
if (error) {
console.error("failed to fetch members", error);
}
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
// Do something with the members array
}
>
Get Members
</Web3Button>
);
}