Usage
Parameters
The hook accepts an object with:
params (ApproveHookInput):
encryptKey (string): User’s decryption PIN
wallet (WalletData): Wallet public/private key pair
contractAddress (string): Token contract to approve
spender (string): Contract address to authorize
amount (number): Maximum spend allowance (will be converted to string internally)
decimals (number, optional): Token decimals (default: 18)
usePasskey (boolean, optional): Set true when encryptKey was derived from a passkey
bearerToken (string): Bearer token for authentication
Return Value
Returns an object containing:
approve: Function to trigger token approval (fire-and-forget)
approveAsync: Promise-based function that resolves with the transaction hash
data: Transaction hash of the approval (string | undefined)
isLoading: Boolean indicating if the operation is in progress
isError: Boolean indicating if an error occurred
error: Error instance when isError is true, otherwise null
isSuccess: Boolean indicating if the approval completed successfully
reset: Function to reset the mutation state
Example Implementation for Approving VESU
Security Considerations
- Always use encrypted private keys
- Never store or transmit raw private keys
- Implement proper PIN validation
- Use secure storage for wallet data
- Consider implementing approval limits
Error Handling
- Handle insufficient token balance
- Validate contract addresses
- Check for existing approvals
- Monitor gas fees
- Implement retry logic for failed transactions
Approvals are specific to each token-contract pair. You’ll need to re-approve when interacting with new contracts.
Related Hooks
- useTransfer - For moving tokens
- useCallAnyContract - For custom contract interactions that need prior approval