Skip to main content

useRevokeRole

Hook for revoking a role from a smart contract that implements the Roles interface.

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

Usage

Provide the contract instance as the argument.

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

// Your smart contract address
const contractAddress = "{{contract_address}}";

function App() {
const { contract } = useContract(contractAddress);
const { mutateAsync: revokeRole, isLoading, error } = useRevokeRole(contract);

if (error) {
console.error("failed to revoke role", error);
}

return (
<Web3Button
contractAddress={contractAddress}
action={() =>
revokeRole({
role: "{{role_name}}",
address: "{{wallet_address}}", // Use useAddress hook to get current wallet address
})
}
>
Revoke Role
</Web3Button>
);
}

Configuration

role

The role argument should be provided as a string.

It should match a role declared in the smart contract.

address

The address argument should be provided as a valid Ethereum wallet address.

You can use the useAddress hook to get this value.

import { useRevokeRole, useContract, Web3Button, useAddress } from "@thirdweb-dev/react";

// Your smart contract address
const contractAddress = "{{contract_address}}";

function App() {
const address = useAddress();
const { contract } = useContract(contractAddress);
const { mutateAsync: revokeRole, isLoading, error } = useRevokeRole(contract);

if (error) {
console.error("failed to revoke role", error);
}

return (
<Web3Button
contractAddress={contractAddress}
action={() =>
revokeRole({
role: "{{role_name}}",
address: address, // Use useAddress hook to get current wallet address
})
}
>
Revoke Role
</Web3Button>
);
}