Reading Balances
balanceOf(address) — Returns ctUint256
// ABI fragment
const abi = [
"function balanceOf(address) view returns (tuple(uint256 ciphertextHigh, uint256 ciphertextLow))"
];
const contract = new ethers.Contract(tokenAddress, abi, provider);
const encryptedBalance = await contract.balanceOf(userAddress);
// Decrypt with COTI SDK
const { decryptUint256 } = require("@coti-io/coti-sdk-typescript");
const decrypted = decryptUint256(
{ ciphertextHigh: encryptedBalance.ciphertextHigh, ciphertextLow: encryptedBalance.ciphertextLow },
aesKeyHex // 32 hex char string, no 0x prefix
);
const formatted = ethers.formatUnits(decrypted, 18);
console.log("Balance:", formatted);Encryption Address (setAccountEncryptionAddress)
Last updated
Was this helpful?