Skip to main content

Module transaction

Module transaction 

Source
Expand description

Re-export the entire miden_client crate so external projects can use a single dependency. Provides APIs for creating, executing, proving, and submitting transactions to the Miden network.

§Overview

This module enables clients to:

  • Build transaction requests using the TransactionRequestBuilder.
  • Execute transactions via the local transaction executor and generate a TransactionResult that includes execution details and relevant notes for state tracking.
  • Prove transactions (locally or remotely) using a TransactionProver and submit the proven transactions to the network.
  • Track and update the state of transactions, including their status (e.g., Pending, Committed, or Discarded).

§Example

The following example demonstrates how to create and submit a transaction:

use miden_client::Client;
use miden_client::auth::TransactionAuthenticator;
use miden_client::crypto::FeltRng;
use miden_client::transaction::{PaymentNoteDescription, TransactionRequestBuilder};
use miden_protocol::account::AccountId;
use miden_protocol::asset::FungibleAsset;
use miden_protocol::note::NoteType;

/// Executes, proves and submits a P2ID transaction.
///
/// This transaction is executed by `sender_id`, and creates an output note
/// containing 100 tokens of `faucet_id`'s fungible asset.
async fn create_and_submit_transaction<
    R: rand::Rng,
    AUTH: TransactionAuthenticator + Sync + 'static,
>(
    client: &mut Client<AUTH>,
    sender_id: AccountId,
    target_id: AccountId,
    faucet_id: AccountId,
) -> Result<(), Box<dyn Error>> {
    // Create an asset representing the amount to be transferred.
    let asset = FungibleAsset::new(faucet_id, 100)?;

    // Build a transaction request for a pay-to-id transaction.
    let tx_request = TransactionRequestBuilder::new().build_pay_to_id(
        PaymentNoteDescription::new(vec![asset.into()], sender_id, target_id),
        NoteType::Private,
        client.rng(),
    )?;

    // Execute, prove, and submit the transaction in a single call.
    let _tx_id = client.submit_new_transaction(sender_id, tx_request).await?;

    Ok(())
}

For more detailed information about each function and error type, refer to the specific API documentation.

Structs§

AccountInterface
An AccountInterface describes the exported, callable procedures of an account.
AdviceInputs
Inputs container to initialize advice provider for the execution of Miden VM programs.
AdviceMap
Defines a set of non-deterministic (advice) inputs which the VM can access by their keys.
ExecutedTransaction
Describes the result of executing a transaction program for the Miden protocol.
InputNotes
Input notes for a transaction, empty if the transaction does not consume notes.
LocalTransactionProver
Local Transaction prover is a stateless component which is responsible for proving transactions.
OutputNotes
Contains a list of output notes of a transaction. The list can be empty if the transaction does not produce any notes.
PaymentNoteDescription
Contains information needed to create a payment note.
ProvenTransaction
Result of executing and proving a transaction. Contains all the data required to verify that a transaction was executed correctly.
ProvingOptions
A set of parameters specifying how Miden VM execution proofs are to be generated.
SwapTransactionData
Contains information related to a swap transaction.
TransactionArgs
Optional transaction arguments.
TransactionDetails
Describes the details associated with a transaction.
TransactionId
A unique identifier of a transaction.
TransactionInputs
Contains the data required to execute a transaction.
TransactionKernel
TransactionRecord
Describes a transaction that has been executed and is being tracked on the Client.
TransactionRequest
Specifies a transaction request that can be executed by an account.
TransactionRequestBuilder
A builder for a TransactionRequest.
TransactionResult
Represents the result of executing a transaction by the client.
TransactionScript
Transaction script.
TransactionStoreUpdate
Represents the changes that need to be applied to the client store as a result of a transaction execution.
TransactionSummary
The summary of the changes that result from executing a transaction.

Enums§

AccountComponentInterface
The enum holding all possible account interfaces which could be loaded to some account.
DataStoreError
DiscardCause
Represents the cause of the discarded transaction.
ForeignAccount
Account types for foreign procedure invocation.
InputNote
An input note for a transaction.
OutputNote
The types of note outputs supported by the transaction kernel.
TransactionExecutorError
TransactionProverError
TransactionRequestError
TransactionScriptTemplate
Specifies a transaction script to be executed in a transaction.
TransactionStatus
Represents the status of a transaction.
TransactionStatusVariant

Traits§

TransactionAuthenticator
Defines an authenticator for transactions.
TransactionProver

Functions§

notes_from_output
Extracts notes from OutputNotes. Used for:

Type Aliases§

NoteArgs