Skip to content

Commit

Permalink
Merge pull request #173 from alexdwagner/main
Browse files Browse the repository at this point in the history
Added docs for getProof, transactionSerializer, and getArgsFromTransactionDepositedOpaqueData.
  • Loading branch information
zencephalon authored Feb 6, 2024
2 parents cecb9af + f433c1b commit 2143b7c
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 0 deletions.
10 changes: 10 additions & 0 deletions site/docs/utilities/deposits/getL2HashFromL1DepositInfo.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
---
head:
- - meta
- property: og:title
content: getL2HashFromL1DepositInfo
- - meta
- name: description
content: Get the L2 transaction hash for a given L1 deposit transaction.
---

# getL2HashFromL1DepositInfo

Get the L2 transaction hash for a given L1 deposit transaction.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
head:
- - meta
- property: og:title
content: getArgsFromTransactionDepositedOpaqueData
- - meta
- name: description
content: Parses the opaque data from the `TransactionDepositedEvent` event args, extracting and structuring key transaction data.
---

# getArgsFromTransactionDepositedOpaqueData

Parses the opaque data from the `TransactionDepositedEvent` event args, returning structured transaction data.

This function is a key component in the `getDepositTransaction` process, where it extracts and formats fields like `mint`, `value`, `gas`, `isCreation`, and `data` from the opaque data. These fields are then used to construct a `DepositTransaction` object.

## Import

```ts
import { parseOpaqueData } from './utils/getArgsFromTransactionDepositedOpaqueData.js';
```

## Usage

```ts
import { parseOpaqueData } from './utils/getArgsFromTransactionDepositedOpaqueData.js';

// ... within getDepositTransaction function
const parsedOpaqueData = parseOpaqueData(event.args.opaqueData);
// Use parsedOpaqueData to construct DepositTransaction
```

## Returns

`ParsedTransactionDepositedOpaqueData`

Returns an object containing structured transaction data with fields such as mint, value, gas, isCreation, and data.

## Parameters

`opaqueData`

**Type:** Hex
**Description:** The opaque data from the TransactionDepositedEvent event args.
48 changes: 48 additions & 0 deletions site/docs/utilities/transactionHelpers/transactionSerializer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
head:
- - meta
- property: og:title
content: transactionSerializer
- - meta
- name: description
content: Add here.
---

# transactionSerializer

Serializes a transaction compliant with Ethereum Improvement Proposal (EIP) 1559.

This utility function takes transaction parameters and serializes them into a format compatible with EIP-1559, which introduced a new transaction type to Ethereum's fee market. It is essential for applications interacting with Ethereum's Layer 1 and Layer 2 solutions, particularly in scenarios where precise gas fee calculations and transaction structuring are required.

## Import

```ts
import { serializeEip1559Transaction } from './utils/transactionSerializer.js';
```

## Usage

```ts
// Example usage in an Ethereum transaction
import { serializeEip1559Transaction } from './utils/transactionSerializer.js';
// Additional imports...

const serializedTx = serializeEip1559Transaction({
// Transaction parameters...
});
// Use serializedTx for further processing...
```

## Parameters

`options`: Combination of `EncodeFunctionDataParameters` and `TransactionSerializableEIP1559` (excluding `data`).

**Type:** Object
**Details:** Contains all the necessary parameters to encode function data and serialize the transaction.

## Returns

`TransactionSerializedEIP1559`

**Type:** Object
**Description:** The serialized transaction data, formatted according to EIP-1559 standards.
70 changes: 70 additions & 0 deletions site/docs/utilities/withdrawals/getProof.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
head:
- - meta
- property: og:title
content: getProof
- - meta
- name: description
content: Generates a proof of account state and storage for a specified Ethereum address at a given block.

---

# getProof

Generates a proof of account state and storage for a specified Ethereum address at a given block.

This function is crucial for verifying the state of an Ethereum account, particularly in applications dealing with cross-chain operations, such as withdrawals from Layer 2 to Layer 1 networks. It fetches proofs for given storage keys of an account at a specific block.

## Import

```ts
import { getProof } from './getProof.js'
```

## Usage

This example, adapted from `getProof.test.js`, demonstrates fetching an account's state and storage proof for a specific Ethereum address at a given block. It illustrates a practical application of the `getProof` function.

```ts
import { createPublicClient, http, toHex } from 'viem';
import { base } from 'viem/chains';
import { getProof } from './getProof.js'

// Setting up the client with base chain and HTTP transport
const client = createPublicClient({
chain: base,
transport: http(),
});

// Example usage of getProof to fetch account state and storage proof
const result = await getProof(client, {
address: '0x4200000000000000000000000000000000000016', // Ethereum address
storageKeys: [
'0x4a932049252365b3eedbc5190e18949f2ec11f39d3bef2d259764799a1b27d99', // Storage key
],
block: toHex(3155269n), // Block number in hexadecimal
});

// The result contains the storage proof for the specified address and block
```

This approach not only provides a clear, practical example of how to use `getProof` but also shows the function in action in a scenario similar to what users might encounter in their own applications.

## Parameters

* `client`: An instance of PublicClient. Responsible for making the request to the Ethereum node.
* `GetProofParameters`: An object containing:
* `address`: The Ethereum address for which to get the proof.
* `storageKeys`: An array of storage keys (Hex) to fetch the storage proof.
* `block`: The block number (Hex or BigInt), tag ('latest', 'earliest', 'pending'), or hash at which to fetch the proof.

## Returns

`AccountProof`: An object containing:

* `address`: The Ethereum address.
* `accountProof`: Array of hex strings forming the Merkle-Patricia proof of the account's existence and state.
* `balance`: Account's balance at the specified block.
* `nonce`: Account's nonce at the specified block.
* `storageHash`: Hash of the storage root.
* `storageProof`: Array of `StorageProof` objects for each requested storage key.

0 comments on commit 2143b7c

Please sign in to comment.