useEncryptedBalance
The useEncryptedBalance hook provides developers with an interface to manage encrypted token balances within the eERC protocol. This includes accessing decrypted and encrypted balances, as well as performing key actions such as minting, burning, transferring tokens, and fetching updated balance data. The hook is designed to simplify balance management while leveraging the protocol’s encryption and privacy features.
Usage
Parameters
tokenAddress(optional) :0x${string}The address of the underlying ERC20 token. This parameter is only required in converter mode.
Returns
decryptedBalance: bigintThe user’s decrypted token balanceparsedDecryptedBalance: stringThe user’s decrypted token balance as a string.auditorPublicKey: bigint[]Auditor Public key.encryptedBalance: bigint[]Encrypted balance of the user as an arraydecimals: bigintEncrypted token decimals
Methods
privateMint(recipient: string, amount: bigint, message?: string): Promise<{ transactionHash: string }>Mints encrypted tokens for a specified recipient address. This action can only be performed by the contract owner.privateBurn(amount: bigint, message?: string): Promise<{ transactionHash: string }>Burns a specified amount of encrypted tokens from the user’s balance.privateTransfer(to: string, amount: bigint, message?: string): Promise<{ transactionHash: string, receiverEncryptedAmount: string[], senderEncryptedAmount: string[] }>Transfers encrypted tokens to another user.withdraw(amount: bigint, message?: string): Promise<{ transactionHash: string }>Withdraws a specified amount of tokens from the user’s balance to underlying ERC20 token address. Only available in converter mode.deposit(amount: bigint, message?: string): Promise<{ transactionHash: string }>Converts a specified amount of ERC20 tokens to private Encrypted ERC tokens. Only available in converter mode.decryptMessage(transactionHash: string): Promise<{ decryptedMessage: string, messageType: string, messageFrom: string, messageTo: string }>Decrypts the private message from the transaction hash. messageType points the operation that the message included in.decryptTransaction(transactionHash: string): Promise<{ decryptedAmount: bigint, from: string, to: string, transactionHash: string, eventType: string, blockNumber: bigint}>Decrypts the private transaction from the transaction hash.refetchBalance(): voidRefetches and updates the user’s encrypted and decrypted balances from the contract.
If you need more help, explore our other articles or reach out to our support team via chat or email [email protected]. All examples provided are for demonstration purposes only.
Learn More About AvaCloud | Download Case Studies | Schedule an AvaCloud Demo