Skip to main content

PendingTransaction

type PendingTransaction = Pick<TransactionCommon, "transaction" | "toJSON" | "toPretty"> & {
data?: SendZkAppResponse;
errors: string[];
hash: string;
status: PendingTransactionStatus;
safeWait: Promise<
| RejectedTransaction
| IncludedTransaction>;
setFee: TransactionPromise<boolean, false>;
setFeePerAccountUpdate: TransactionPromise<boolean, false>;
wait: Promise<IncludedTransaction>;
};

Defined in: lib/mina/v1/transaction.ts:207

Represents a transaction that has been submitted to the blockchain but has not yet reached a final state. The PendingTransaction type extends certain functionalities from the base Transaction type, adding methods to monitor the transaction's progress towards being finalized (either included in a block or rejected).

Type declaration​

data?​

optional data: SendZkAppResponse;

Optional. Contains response data from a ZkApp transaction submission.

errors​

errors: string[];

An array of error messages related to the transaction processing.

Example​

if (!pendingTransaction.status === 'rejected') {
console.error(`Transaction errors: ${pendingTransaction.errors.join(', ')}`);
}

hash​

hash: string;

Returns the transaction hash as a string identifier.

Example​

const txHash = pendingTransaction.hash;
console.log(`Transaction hash: ${txHash}`);

status​

status: PendingTransactionStatus;

Example​

if (pendingTransaction.status === 'pending') {
console.log('Transaction accepted for processing by the Mina daemon.');
try {
await pendingTransaction.wait();
console.log('Transaction successfully included in a block.');
} catch (error) {
console.error('Transaction was rejected or failed to be included in a block:', error);
}
} else {
console.error('Transaction was not accepted for processing by the Mina daemon.');
}

safeWait()​

safeWait(options?: {
interval?: number;
maxAttempts?: number;
}): Promise<
| RejectedTransaction
| IncludedTransaction>;

Waits for the transaction to be included in a block. This method polls the Mina daemon to check the transaction's status

Parameters​

options?​

Configuration options for polling behavior.

interval?​

number

The time interval, in milliseconds, between each polling attempt.

maxAttempts?​

number

The maximum number of polling attempts.

Returns​

Promise< | RejectedTransaction | IncludedTransaction>

A promise that resolves to the transaction's final state.

Example​

const transaction = await pendingTransaction.wait({ maxAttempts: 5, interval: 1000 });
console.log(transaction.status); // 'included' or 'rejected'

setFee()​

setFee(newFee: UInt64): TransactionPromise<boolean, false>;

setFee is the same as (newFee) but for a PendingTransaction.

Parameters​

newFee​

UInt64

Returns​

TransactionPromise<boolean, false>

setFeePerAccountUpdate()​

setFeePerAccountUpdate(newFeePerAccountUpdate: number): TransactionPromise<boolean, false>;

setFeePerAccountUpdate is the same as (newFeePerAccountUpdate) but for a PendingTransaction.

Parameters​

newFeePerAccountUpdate​

number

Returns​

TransactionPromise<boolean, false>

wait()​

wait(options?: {
interval?: number;
maxAttempts?: number;
}): Promise<IncludedTransaction>;

Waits for the transaction to be included in a block. This method polls the Mina daemon to check the transaction's status, and throws an error if the transaction is rejected.

Parameters​

options?​

Configuration options for polling behavior.

interval?​

number

The interval, in milliseconds, between status checks.

maxAttempts?​

number

The maximum number of attempts to check the transaction status.

Returns​

Promise<IncludedTransaction>

A promise that resolves to the transaction's final state or throws an error.

Throws​

If the transaction is rejected or fails to finalize within the given attempts.

Example​

try {
const transaction = await pendingTransaction.wait({ maxAttempts: 10, interval: 2000 });
console.log('Transaction included in a block.');
} catch (error) {
console.error('Transaction rejected or failed to finalize:', error);
}