Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions docs/docs-developers/docs/foundational-topics/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,22 @@ In Aztec.js:
Where:

- `origin` is the account contract where the transaction is initiated from.
- `argsHash` is the hash of the arguments of the entrypoint call. The complete set of arguments is passed to the PXE as part of the [TxExecutionRequest](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/yarn-project/stdlib/src/tx/tx_execution_request.ts) and checked against this hash.
- `argsHash` is the hash of the arguments of the entrypoint call. The complete set of arguments is passed to the PXE as part of the `TxExecutionRequest` and checked against this hash.
- `txContext` contains the chain id, version, and gas settings.
- `functionData` contains the function selector and indicates whether the function is private or public.
- `salt` is used to make the transaction request hash difficult to predict. The hash is used as the first nullifier if no nullifier is emitted throughout the transaction.

An account contract validates that the transaction request has been authorized via its specified authorization mechanism, via the `is_valid_impl` function (e.g. [an ECDSA signature](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/noir-contracts/contracts/account/ecdsa_k_account_contract/src/main.nr)).
The `TxExecutionRequest` class:

Transaction requests are simulated in the PXE in order to generate the necessary inputs for generating proofs. Once transactions are proven, a [transaction object](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/yarn-project/stdlib/src/tx/tx.ts#L26) is created and can be sent to the network to be included in a block.
#include_code tx_execution_request_class yarn-project/stdlib/src/tx/tx_execution_request.ts javascript

An account contract validates that the transaction request has been authorized via its specified authorization mechanism, via the `is_valid_impl` function. Here is an example using an ECDSA signature:

#include_code is_valid_impl noir-projects/noir-contracts/contracts/account/ecdsa_k_account_contract/src/main.nr rust

Transaction requests are simulated in the PXE in order to generate the necessary inputs for generating proofs. Once transactions are proven, a `Tx` object is created and can be sent to the network to be included in a block:

#include_code tx_class yarn-project/stdlib/src/tx/tx.ts javascript

#### Contract Interaction Methods

Expand All @@ -75,7 +83,9 @@ Most transaction requests are created as interactions with specific contracts. T

### Batch Transactions

Batched transactions are a way to send multiple transactions in a single call. They are created by the [`BatchCall` class in Aztec.js](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/yarn-project/aztec.js/src/contract/batch_call.ts). This allows a batch of function calls from a single wallet to be sent as a single transaction through a wallet.
Batched transactions are a way to send multiple transactions in a single call. They are created by the `BatchCall` class in Aztec.js. This allows a batch of function calls from a single wallet to be sent as a single transaction through a wallet.

#include_code batch_call_class yarn-project/aztec.js/src/contract/batch_call.ts javascript

### Enabling Transaction Semantics

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub contract EcdsaKAccount {
actions.verify_private_authwit(inner_hash)
}

// docs:start:is_valid_impl
#[contract_library_method]
fn is_valid_impl(context: &mut PrivateContext, outer_hash: Field) -> bool {
// Load public key from storage
Expand All @@ -100,4 +101,5 @@ pub contract EcdsaKAccount {
hashed_message,
)
}
// docs:end:is_valid_impl
}
2 changes: 2 additions & 0 deletions yarn-project/aztec.js/src/contract/batch_call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import {
} from './interaction_options.js';

/** A batch of function calls to be sent as a single transaction through a wallet. */
// docs:start:batch_call_class
export class BatchCall extends BaseContractInteraction {
constructor(
wallet: Wallet,
protected interactions: (BaseContractInteraction | ExecutionPayload)[],
) {
super(wallet);
}
// docs:end:batch_call_class

/**
* Returns an execution request that represents this operation.
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/stdlib/src/tx/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { TxHash } from './tx_hash.js';
/**
* The interface of an L2 transaction.
*/
// docs:start:tx_class
export class Tx extends Gossipable {
static override p2pTopic = TopicType.tx;

Expand Down Expand Up @@ -60,6 +61,7 @@ export class Tx extends Gossipable {
) {
super();
}
// docs:end:tx_class

// Gossipable method
override generateP2PMessageIdentifier(): Promise<Buffer32> {
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/stdlib/src/tx/tx_execution_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { TxRequest } from './tx_request.js';
/**
* Request to execute a transaction. Similar to TxRequest, but has the full args.
*/
// docs:start:tx_execution_request_class
export class TxExecutionRequest {
constructor(
/**
Expand Down Expand Up @@ -60,6 +61,7 @@ export class TxExecutionRequest {
*/
public salt = Fr.random(),
) {}
// docs:end:tx_execution_request_class

static get schema(): ZodFor<TxExecutionRequest> {
return z
Expand Down
Loading