Hooks
useApprove
Grants permission to a smart contract to spend tokens from the user wallet. Required before staking or other delegated actions.
Usage
Parameters
encryptKey
(string): User’s decryption PINwallet
(WalletData): Wallet public/private key paircontractAddress
(string): Token contract to approvespender
(string): Contract address to authorizeamount
(string | number): Maximum spend allowancedecimals
(number): Token decimals (default: 18)
Return Value
Returns an object containing:
approveAsync
: Function to trigger token approvalapproveData
: Transaction hash of the approvalisLoading
: Boolean indicating if the operation is in progresserror
: Any error that occurred during the process
Example Implementation
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.