Precompiles Hooks
Hooks for interacting with Avalanche precompiled contracts.
Precompile Hooks
BuilderKit provides a set of React hooks for interacting with Avalanche's precompiled contracts. These hooks simplify the interaction with L1-level functionality and administrative operations.
Available Hooks
Integration with Transaction Components
All precompile hooks return transaction data that can be used with the TransactionButton or TransactionManager components.
function App() {
const { mintNativeCoin } = useNativeMinter();
const handleMint = () => {
const data = mintNativeCoin("0x1234...", "0x1000000000000000");
return (
<TransactionButton
chain_id={43114}
title="Mint Tokens"
description="Minting native tokens"
data={data}
/>
);
};
}
Access Control with useAllowList
Most precompiles in Avalanche use a role-based access control system managed through the useAllowList
hook. This means that before using precompile functions, you need to ensure the calling address has the appropriate role.
The role system has three levels:
- None (0): No permissions
- Enabled (1): Basic permissions for operations
- Admin (2): Full control over the precompile
Here's how roles work across precompiles:
Precompile | Required Role | Operations |
---|---|---|
NativeMinter | Admin | - Set roles for other addresses - Mint native tokens |
Enabled | - Mint native tokens | |
FeeManager | Admin | - Set roles for other addresses - Configure gas fees - Set minimum block cost - Set block gas cost step |
RewardManager | Admin | - Set roles for other addresses - Configure reward address - Enable/disable fee recipients - Set reward address |
WarpMessenger | Admin | - Set roles for other addresses - Send cross-chain messages - Get verified messages |
Enabled | - Send cross-chain messages - Get verified messages | |
TransactionAllowList | Admin | - Set roles for other addresses - Enable/disable addresses for transactions |
Enabled | - Submit transactions (if enabled) | |
DeployerAllowList | Admin | - Set roles for other addresses - Enable/disable addresses for deployments |
Enabled | - Deploy contracts (if enabled) |
Example of checking and setting roles:
function AdminPanel() {
const { readAllowList, setEnabled, setAdmin, setNone } = useAllowList(precompileAddress);
// Check current role
const checkAccess = async (address) => {
const role = await readAllowList(43114, address);
return role; // Returns: 0 (None), 1 (Enabled), 2 (Admin)
};
// Grant Enabled role
const grantEnabled = async (address) => {
const data = setEnabled(address);
return (
<TransactionButton
chain_id={43114}
title="Grant Access"
description="Granting enabled role"
data={data}
/>
);
};
// Grant Admin role
const grantAdmin = async (address) => {
const data = setAdmin(address);
return (
<TransactionButton
chain_id={43114}
title="Grant Admin"
description="Granting admin role"
data={data}
/>
);
};
// Remove all roles
const removeAccess = async (address) => {
const data = setNone(address);
return (
<TransactionButton
chain_id={43114}
title="Remove Access"
description="Removing all roles"
data={data}
/>
);
};
}
Precompile Addresses
Precompile | Address | Description |
---|---|---|
NativeMinter | 0x0200000000000000000000000000000000000001 | Mint native tokens |
TransactionAllowList | 0x0200000000000000000000000000000000000002 | Control transaction permissions |
FeeManager | 0x0200000000000000000000000000000000000003 | Configure chain fees |
RewardManager | 0x0200000000000000000000000000000000000004 | Manage reward distribution |
WarpMessenger | 0x0200000000000000000000000000000000000005 | Cross-chain messaging |
DeployerAllowList | 0x0200000000000000000000000000000000000000 | Control deployment permissions |