Usage
Parameters
The hook accepts an object with:params(ApproveHookInput):encryptKey(string): User’s decryption PINwallet(WalletData): Wallet public/private key paircontractAddress(string): Token contract to approvespender(string): Contract address to authorizeamount(number): Maximum spend allowance (will be converted to string internally)decimals(number, optional): Token decimals (default: 18)usePasskey(boolean, optional): SettruewhenencryptKeywas 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 hashdata: Transaction hash of the approval (string | undefined)isLoading: Boolean indicating if the operation is in progressisError: Boolean indicating if an error occurrederror: Error instance whenisErroris true, otherwisenullisSuccess: Boolean indicating if the approval completed successfullyreset: 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
Related Hooks
- useTransfer - For moving tokens
- useCallAnyContract - For custom contract interactions that need prior approval
