Account Class API Reference
Complete API reference for the Account class.
Constructor
new Account(
pk: BigNumberish | Uint8Array,
contractAddress: string,
provider: RpcProvider
): Account
Parameters:
pk: Private key as bigint or Uint8ArraycontractAddress: Tongo contract addressprovider: Starknet RPC provider
Example:
const account = new TongoAccount(privateKey, tongoAddress, provider);
Static Methods
tongoAddress()
Get Tongo address from a private key without creating an Account.
static tongoAddress(pk: BigNumberish | Uint8Array): TongoAddress
Properties
publicKey
publicKey: PubKey
The account's public key (elliptic curve point).
pk
pk: bigint
The account's private key (internal, don't access directly).
State Methods
state()
Get decrypted account state.
async state(): Promise<AccountState>
Returns:
{
balance: bigint;
pending: bigint;
nonce: bigint;
}
rawState()
Get encrypted account state.
async rawState(): Promise<RawAccountState>
Returns:
{
balance: CipherBalance;
pending: CipherBalance;
audit?: CipherBalance;
nonce: bigint;
aeBalance?: AEBalance;
aeAuditBalance?: AEBalance;
}
nonce()
Get account nonce.
async nonce(): Promise<bigint>
tongoAddress()
Get base58-encoded Tongo address.
tongoAddress(): TongoAddress
Operation Methods
fund()
Create a fund operation.
async fund(details: FundDetails): Promise<FundOperation>
Parameters:
interface FundDetails {
amount: bigint;
}
transfer()
Create a transfer operation.
async transfer(details: TransferDetails): Promise<TransferOperation>
Parameters:
interface TransferDetails {
amount: bigint;
to: PubKey;
}
withdraw()
Create a withdraw operation.
async withdraw(details: WithdrawDetails): Promise<WithdrawOperation>
Parameters:
interface WithdrawDetails {
to: string; // Starknet address
amount: bigint;
}
rollover()
Create a rollover operation.
async rollover(): Promise<RollOverOperation>
ragequit()
Create a ragequit operation.
async ragequit(details: RagequitDetails): Promise<RagequitOperation>
Parameters:
interface RagequitDetails {
to: string; // Starknet address
}
Utility Methods
rate()
Get contract conversion rate.
async rate(): Promise<bigint>
erc20ToTongo()
Convert ERC20 amount to Tongo amount (approximate).
async erc20ToTongo(erc20Amount: bigint): Promise<bigint>
tongoToErc20()
Convert Tongo amount to ERC20 amount (exact).
async tongoToErc20(tongoAmount: bigint): Promise<bigint>
Decryption Methods
decryptCipherBalance()
Decrypt a CipherBalance.
decryptCipherBalance(cipher: CipherBalance, hint?: bigint): bigint
decryptAEBalance()
Decrypt an AEBalance hint.
async decryptAEBalance(aeBalance: AEBalance, accountNonce: bigint): Promise<bigint>
Event Methods
getTxHistory()
Get complete transaction history.
async getTxHistory(initialBlock: number): Promise<AccountEvents[]>
getEventsFund()
Get fund events.
async getEventsFund(initialBlock: number): Promise<AccountFundEvent[]>
getEventsTransferOut()
Get transfer out events.
async getEventsTransferOut(initialBlock: number): Promise<AccountTransferOutEvent[]>
getEventsTransferIn()
Get transfer in events.
async getEventsTransferIn(initialBlock: number): Promise<AccountTransferInEvent[]>
getEventsRollover()
Get rollover events.
async getEventsRollover(initialBlock: number): Promise<AccountRolloverEvent[]>
getEventsWithdraw()
Get withdraw events.
async getEventsWithdraw(initialBlock: number): Promise<AccountWithdrawEvent[]>
getEventsRagequit()
Get ragequit events.
async getEventsRagequit(initialBlock: number): Promise<AccountRagequitEvent[]>
Audit Methods
generateExPost()
Generate ex-post proof for a transfer.
generateExPost(to: PubKey, cipher: CipherBalance): ExPost
verifyExPost()
Verify an ex-post proof.
verifyExPost(expost: ExPost): bigint