Defining functions
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. Twotransfer()
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, formingeinput
andinputProof
using thefhevmjs
library on the client side. Learn more about this here.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 theencryptedAmount
that aspender
is permitted to be used on behalf of the caller. There are two versions ofapprove()
with the same name but different function signatures, similar to thetransfer()
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 oftransferFrom()
with the same name but different function signatures, similar to thetransfer()
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 thefhevmJs
library and making a call to theGateway
. Refer to this guide.Allowances:
The
allowance
function returns the handle to the ciphertext representing the amount that a specifiedspender
is allowed to spend on behalf of theowner
. This handle can be used on the client side to retrieve the allowance amount by leveraging thefhevmJs
library and making a call to theGateway
.Refer to this guide.
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.
Last updated