@fairblock/stabletrust SDK exposes two clients:
ConfidentialTransferClient: direct onchain transfers with encrypted amounts (sender address visible). Covered below.AnonymousTransferClient: relay-routed transfers that also hide the sender’s address. Signatures are listed below; see the Unlinkable Transfers guide for usage.
Amount types.
confidentialDeposit takes a BigInt (base units, from ethers.parseUnits). confidentialTransfer and withdraw take a number (cast with Number(ethers.parseUnits(...))).ConfidentialTransferClient
Manages direct onchain interactions with the confidential transfer contract. Amounts and balances are encrypted with homomorphic encryption; the sender’s wallet address remains visible onchain.Constructor
ensureAccount(wallet, options?)
Creates a confidential account onchain (if one doesn’t exist) and waits for finalization. Must be called before any confidential operation.
- Returns:
{ publicKey, privateKey }: derived ElGamal keypair for this wallet. options.waitForFinalization(defaulttrue): wait for the account to be finalized.options.maxAttempts(default225): maximum polling attempts.
getAccountInfo(address)
Fetches onchain account state: exists, finalized, elgamalPubkey, txId, etc.
getConfidentialBalance(address, privateKey, tokenAddress)
Decrypts and returns the available and pending balances.
- Returns:
{ amount, available: { amount, ciphertext }, pending: { amount, ciphertext } }
confidentialDeposit(wallet, tokenAddress, amount, options?)
Deposits ERC-20 tokens into the confidential contract. Handles ERC-20 approval automatically. amount is a BigInt in token base units.
- Returns: Transaction receipt.
confidentialTransfer(senderWallet, recipientAddress, tokenAddress, amount, options?)
Transfers a confidential amount to a recipient. The recipient must have an existing confidential account. amount is a number in token base units.
- Returns: Transaction receipt.
withdraw(wallet, tokenAddress, amount, options?)
Withdraws from the confidential available balance back to public ERC-20. amount is a number in token base units.
- Returns: Transaction receipt.
getFeeToken()
Returns the fee-token address for the current chain (address(0) = native currency).
getNonAnonymousTransferFee()
Returns the protocol fee for a direct confidential transfer, in the fee token’s base units.
getPublicBalance(address, tokenAddress)
Returns the public ERC-20 balance for an address as a BigInt.
AnonymousTransferClient
Routes all operations through the Fairycloak relay, which pays gas (except deposits) and keeps the sender’s wallet address offchain. See the Unlinkable Transfers guide for setup, account-ID rules, and end-to-end examples.Constructor
Accounts & keys
Balances
Moving funds
Prepaid fees
Request tracking
All relay operations return{ request_id, tx_hash, status }.