@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. A fixed fee may be charged in the fee token at request time. An optional percentage of the withdrawn tokens may also be taken on success, so the wallet can receive less than amount.
- Returns: Transaction receipt.
getFeeToken()
Returns the fee token address for the current chain (address(0) = native currency).
getNonAnonymousTransferFee()
Returns the fixed fee for a direct confidential transfer, in the fee token’s base units.
getNonAnonymousWithdrawFee()
Returns the fixed fee for a direct confidential withdraw, in the fee token’s base units.
getNonAnonymousWithdrawFeePpm()
Returns the percentage withdraw fee in parts per million (out of 1_000_000). Taken from the withdrawn token on success.
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
enableNativeFeeToken: true (default false) only when the deployment’s fee token is native ETH; leave it off otherwise.
Accounts & keys
Balances
Moving funds
Prepaid fees
Create,updateAuthKeys, transfer, applyPending, and withdraw each charge a fixed fee from the account’s prepaid balance when the request is accepted. createAccount seeds that balance with an initial deposit in the fee token. Top it up any time with depositFees. Withdrawals can also take an optional percentage of the withdrawn tokens on success.
Request tracking
All relay operations return{ request_id, tx_hash, status }.