Skip to main content

Transaction

type Transaction<Proven, Signed> = TransactionCommon & {
safeSend: Promise<
| PendingTransaction
| RejectedTransaction>;
send: PendingTransactionPromise;
setFee: TransactionPromise<Proven, false>;
setFeePerSnarkCost: TransactionPromise<Proven, false>;
} & Proven extends false ? {
prove: Promise<Transaction<true, Signed>>;
} : {
proofs: (
| Proof<ZkappPublicInput, Empty>
| undefined)[];
} & Signed extends false ? {
sign: Transaction<Proven, true>;
} : {};

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

Defines the structure and operations associated with a transaction. This type encompasses methods for serializing the transaction, signing it, generating proofs, and submitting it to the network.

Type declaration

safeSend()

Sends the Transaction to the network. Unlike the standard Transaction.send, this function does not throw an error if internal errors are detected. Instead, it returns a PendingTransaction if the transaction is successfully sent for processing or a RejectedTransaction if it encounters errors during processing or is outright rejected by the Mina daemon.

Returns

Promise< | PendingTransaction | RejectedTransaction>

A promise that resolves to a PendingTransaction if the transaction is accepted for processing, or a RejectedTransaction if the transaction fails or is rejected.

Example

const result = await transaction.safeSend();
if (result.status === 'pending') {
console.log('Transaction sent successfully to the Mina daemon.');
} else if (result.status === 'rejected') {
console.error('Transaction failed with errors:', result.errors);
}

send()

Returns

PendingTransactionPromise

setFee()

Modifies a transaction to set the fee to the new fee provided. Because this change invalidates proofs and signatures both are removed. The nonce is not increased so sending both transitions will not risk both being accepted.

Parameters

newFee

UInt64

Returns

TransactionPromise<Proven, false>

The same transaction with the new fee and the proofs and signatures removed.

Example

tx.send();
// Waits for some time and decide to resend with a higher fee

tx.setFee(newFee);
await tx.sign([feePayerKey]));
await tx.send();

setFeePerSnarkCost()

setFeePerSnarkCost behaves identically to Transaction.setFee but the fee is given per estimated cost of snarking the transition as given by getTotalTimeRequired. This is useful because it should reflect what snark workers would charge in times of network contention.

Parameters

newFeePerSnarkCost

number

Returns

TransactionPromise<Proven, false>

Type Parameters

Proven extends boolean

Signed extends boolean