Defining functions
Last updated
Last updated
Constructor
Constructor - Define the constructor to set the contract deployer as the token owner.
Minting Tokens:
The mint
function creates new tokens and updates the owner's balance. We use TFHE operations to add tokens to the owner's balance.
_mint
allows the contract owner to mint tokens in a confidential manner.
Transferring Tokens:
The transfer
function allows token holders to send tokens to another address. Two transfer()
function versions exist, each with the same name but differing function signatures for different use cases.
transfer(address, einput, bytes)
: This version is used by externally owned accounts (EOA) to call the function, forming einput
and inputProof
using the fhevmjs
library on the client side. Learn more about this .
transfer(address, euint64)
: This version is used by other contracts to interact with our confidential ERC20 contract.
Approving Tokens:
The approve
function allows a token holder to set an allowance, specifying the encryptedAmount
that a spender
is permitted to be used on behalf of the caller. There are two versions of approve()
with the same name but different function signatures, similar to the transfer()
function: one for EOAs and the other for contracts.
Transferring Tokens from Another Address:
The transferFrom
function allows a spender to transfer tokens on behalf of another account, utilizing an approved allowance. There are two versions of transferFrom()
with the same name but different function signatures, similar to the transfer()
function: one for EOAs and the other for contracts.
Viewing encrypted balances and allowances:
Balances:
The balanceOf
function returns the handle to the ciphertext representing a user's balance. This handle can be used on the client side to retrieve the actual balance by leveraging the fhevmJs
library and making a call to the Gateway
. .
Allowances:
The allowance
function returns the handle to the ciphertext representing the amount that a specified spender
is allowed to spend on behalf of the owner
. This handle can be used on the client side to retrieve the allowance amount by leveraging the fhevmJs
library and making a call to the Gateway
..
Decrypting Account Balances: Owner Access and Permissions
The contract owner()
or deployer can access any balance and request global decryption for user balances when needed.