useGrantRole
Hook for granting a role on a smart contract.
Available to use on smart contracts that implement the Permissions interface.
import { useGrantRole, useContract, Web3Button } from "@thirdweb-dev/react";
const { mutateAsync, isLoading, error } = useGrantRole(contract);
Usage
Provide your contract from the useContract
as the argument.
import { useGrantRole, useContract, Web3Button } from "@thirdweb-dev/react";
// Your smart contract address
const contractAddress = "{{contract_address}}";
const roleToGrant = "{{role}}";
const walletAddressToGrant = "{{wallet_address}}";
function App() {
const { contract } = useContract(contractAddress);
const { mutateAsync: grantRole, isLoading, error } = useGrantRole(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
grantRole({
role: roleToGrant, // name of your role.
address: walletAddressToGrant, // address to grant the role to.
})
}
>
Grant Role
</Web3Button>
);
}