useRevokeRole
Hook for revoking a wallet address from a role on a smart contract.
Available to use on contracts that implement Permission Controls.
The wallet address that initiates this transaction must have the relevant permissions on the contract to remove the role from the wallet address (typically admin
level required).
import { useRevokeRole } from "@thirdweb-dev/react";
Usage
Provide your contract instance from the useContract
hook as the argument.
import { useContract, useRevokeRole, Web3Button } from "@thirdweb-dev/react";
// Your smart contract address (must implement permission controls)
const contractAddress = "{{contract_address}}";
const walletAddress = "{{wallet_address}}";
function App() {
// Contract must be a contract that implements the Permission Controls interface
const { contract } = useContract(contractAddress);
const { mutateAsync: revokeRole, isLoading, error } = useRevokeRole(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
revokeRole({
role: "admin",
address: walletAddress,
})
}
>
Revoke Role
</Web3Button>
);
}
Configuration
role (reuqired)
The role to revoke from the wallet address.
Can be any custom role, or a built-in role, such as admin
, transfer
, minter
, pauser
, lister
, asset
, unwrap
, or factory
.
import { useContract, useRevokeRole, Web3Button } from "@thirdweb-dev/react";
// Your smart contract address (must implement permission controls)
const contractAddress = "{{contract_address}}";
const walletAddress = "{{wallet_address}}";
const role = "{{role}}";
function App() {
// Contract must be a contract that implements the Permission Controls interface
const { contract } = useContract(contractAddress);
const { mutateAsync: revokeRole, isLoading, error } = useRevokeRole(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
revokeRole({
role: role,
address: walletAddress,
})
}
>
Revoke Role
</Web3Button>
);
}
address
The wallet address to revoke the role from.
To use the connected wallet address, use the useAddress
hook.
import {
useContract,
useRevokeRole,
Web3Button,
useAddress,
} from "@thirdweb-dev/react";
// Your smart contract address (must implement permission controls)
const contractAddress = "{{contract_address}}";
const role = "{{role}}";
function App() {
// Contract must be a contract that implements the Permission Controls interface
const { contract } = useContract(contractAddress);
const { mutateAsync: revokeRole, isLoading, error } = useRevokeRole(contract);
const address = useAddress();
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
revokeRole({
role: role,
address: address,
})
}
>
Revoke Role
</Web3Button>
);
}