Skip to main content

PendingTransaction

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

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()

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.

options.interval?: number

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

options.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'

wait()

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.

options.interval?: number

The interval, in milliseconds, between status checks.

options.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);
}

Source

lib/mina/transaction.ts:156