Transaction Configuration

Getting transaction parts and maximum amount to transfer/withdraw

Getting Transaction Parts

The user's request to send or withdraw money may produce several transactions to the privacy pool in the common case. It depends on both a local account/notes configuration and transfer destinations amount as well. The following method is used to evaluate transactions needed to process request

async getTransactionParts(
    txType: TxType,
    transfers: TransferRequest[],
    relayerFee?: RelayerFee,
    withdrawSwap: bigint = 0n,
    updateState: boolean = true,
    allowPartial: boolean = false,
): Promise<Array<TransferConfig>>

Parameters

txType is transaction type (a member of TxType enum)

This method supports just a TxType.Transfer and TxType.Withdraw transaction types only (deposits are always performed within single transaction). The internal error will thrown for other tx types

transfers - a set of transfer requests (use single request with requested amount for withdrawal as well)

The request's destination field is ignored in this method

relayerFee - a raw relayer fee object which will be used to estimate total transaction fee (will requested under the hood when undefined)

withdrawSwap is an optional amount of tokens which should swap in withdraw transaction. It may influence the typical withdraw transaction cost due to extra fee component (ignored for other transaction types)

updateState - update the state before parts evaluating

allowPartial - try to build result even in case of insufficient balance

Returns

Promise returns array of TransferConfigs which describe all transactions needed to process input request, or a void array if request cannot be processed (e.g. in case of insufficient funds)

Example

const parts = await zkClient.getTransactionParts(
    TxType.Withdraw,
    [{
        destination: '0x49C92c016d2c7A245aAF5351BD932D9D61536eC0',
        amountGwei: 5000000000n // withdraw 5 BOB
    }],
    undefined,    // fetch relayer fee under the hood
    1000000000,    // swap 1 BOB
);
console.log(`This operation requires ${parts.length} transaction(s)`);
// output: This operation requires 4 transaction(s)

Getting Maximum Available Outgoing Transaction

Calculating maximum available amount for transfers and withdrawals. This estimation doesn't take into account pool contract limits

async calcMaxAvailableTransfer(
    txType: TxType,
    relayerFee?: RelayerFee,
    withdrawSwap: bigint = 0n,
    updateState: boolean = true
): Promise<bigint>
See Also

Parameters

txType is transaction type (a member of TxType enum)

This method supports just a TxType.Transfer and TxType.Withdraw transaction types only (you can deposit any amount in the limit boundaries). The internal error will thrown for other tx types

relayerFee - a raw relayer fee object which will be used to estimate total transaction fee (will requested under the hood when undefined)

withdrawSwap is an optional amount of tokens which should swap in withdraw transaction. It may influence the typical withdraw transaction cost due to extra fee component (ignored for other transaction types)

updateState - update the state before parts evaluating

Returns

Promise returns token amount in the pool dimension

Example

const maxAmount = await zkClient.calcMaxAvailableTransfer(TxType.Transfer);
console.log(`You can transfer up to ${maxAmount} BOB`);
// output: You can transfer up to 234.56 BOB

Last updated