Skip to content

Commit 2143b7c

Browse files
authored
Merge pull request #173 from alexdwagner/main
Added docs for getProof, transactionSerializer, and getArgsFromTransactionDepositedOpaqueData.
2 parents cecb9af + f433c1b commit 2143b7c

File tree

4 files changed

+172
-0
lines changed

4 files changed

+172
-0
lines changed

site/docs/utilities/deposits/getL2HashFromL1DepositInfo.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
---
2+
head:
3+
- - meta
4+
- property: og:title
5+
content: getL2HashFromL1DepositInfo
6+
- - meta
7+
- name: description
8+
content: Get the L2 transaction hash for a given L1 deposit transaction.
9+
---
10+
111
# getL2HashFromL1DepositInfo
212

313
Get the L2 transaction hash for a given L1 deposit transaction.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
head:
3+
- - meta
4+
- property: og:title
5+
content: getArgsFromTransactionDepositedOpaqueData
6+
- - meta
7+
- name: description
8+
content: Parses the opaque data from the `TransactionDepositedEvent` event args, extracting and structuring key transaction data.
9+
---
10+
11+
# getArgsFromTransactionDepositedOpaqueData
12+
13+
Parses the opaque data from the `TransactionDepositedEvent` event args, returning structured transaction data.
14+
15+
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.
16+
17+
## Import
18+
19+
```ts
20+
import { parseOpaqueData } from './utils/getArgsFromTransactionDepositedOpaqueData.js';
21+
```
22+
23+
## Usage
24+
25+
```ts
26+
import { parseOpaqueData } from './utils/getArgsFromTransactionDepositedOpaqueData.js';
27+
28+
// ... within getDepositTransaction function
29+
const parsedOpaqueData = parseOpaqueData(event.args.opaqueData);
30+
// Use parsedOpaqueData to construct DepositTransaction
31+
```
32+
33+
## Returns
34+
35+
`ParsedTransactionDepositedOpaqueData`
36+
37+
Returns an object containing structured transaction data with fields such as mint, value, gas, isCreation, and data.
38+
39+
## Parameters
40+
41+
`opaqueData`
42+
43+
**Type:** Hex
44+
**Description:** The opaque data from the TransactionDepositedEvent event args.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
head:
3+
- - meta
4+
- property: og:title
5+
content: transactionSerializer
6+
- - meta
7+
- name: description
8+
content: Add here.
9+
---
10+
11+
# transactionSerializer
12+
13+
Serializes a transaction compliant with Ethereum Improvement Proposal (EIP) 1559.
14+
15+
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.
16+
17+
## Import
18+
19+
```ts
20+
import { serializeEip1559Transaction } from './utils/transactionSerializer.js';
21+
```
22+
23+
## Usage
24+
25+
```ts
26+
// Example usage in an Ethereum transaction
27+
import { serializeEip1559Transaction } from './utils/transactionSerializer.js';
28+
// Additional imports...
29+
30+
const serializedTx = serializeEip1559Transaction({
31+
// Transaction parameters...
32+
});
33+
// Use serializedTx for further processing...
34+
```
35+
36+
## Parameters
37+
38+
`options`: Combination of `EncodeFunctionDataParameters` and `TransactionSerializableEIP1559` (excluding `data`).
39+
40+
**Type:** Object
41+
**Details:** Contains all the necessary parameters to encode function data and serialize the transaction.
42+
43+
## Returns
44+
45+
`TransactionSerializedEIP1559`
46+
47+
**Type:** Object
48+
**Description:** The serialized transaction data, formatted according to EIP-1559 standards.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
head:
3+
- - meta
4+
- property: og:title
5+
content: getProof
6+
- - meta
7+
- name: description
8+
content: Generates a proof of account state and storage for a specified Ethereum address at a given block.
9+
10+
---
11+
12+
# getProof
13+
14+
Generates a proof of account state and storage for a specified Ethereum address at a given block.
15+
16+
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.
17+
18+
## Import
19+
20+
```ts
21+
import { getProof } from './getProof.js'
22+
```
23+
24+
## Usage
25+
26+
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.
27+
28+
```ts
29+
import { createPublicClient, http, toHex } from 'viem';
30+
import { base } from 'viem/chains';
31+
import { getProof } from './getProof.js'
32+
33+
// Setting up the client with base chain and HTTP transport
34+
const client = createPublicClient({
35+
chain: base,
36+
transport: http(),
37+
});
38+
39+
// Example usage of getProof to fetch account state and storage proof
40+
const result = await getProof(client, {
41+
address: '0x4200000000000000000000000000000000000016', // Ethereum address
42+
storageKeys: [
43+
'0x4a932049252365b3eedbc5190e18949f2ec11f39d3bef2d259764799a1b27d99', // Storage key
44+
],
45+
block: toHex(3155269n), // Block number in hexadecimal
46+
});
47+
48+
// The result contains the storage proof for the specified address and block
49+
```
50+
51+
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.
52+
53+
## Parameters
54+
55+
* `client`: An instance of PublicClient. Responsible for making the request to the Ethereum node.
56+
* `GetProofParameters`: An object containing:
57+
* `address`: The Ethereum address for which to get the proof.
58+
* `storageKeys`: An array of storage keys (Hex) to fetch the storage proof.
59+
* `block`: The block number (Hex or BigInt), tag ('latest', 'earliest', 'pending'), or hash at which to fetch the proof.
60+
61+
## Returns
62+
63+
`AccountProof`: An object containing:
64+
65+
* `address`: The Ethereum address.
66+
* `accountProof`: Array of hex strings forming the Merkle-Patricia proof of the account's existence and state.
67+
* `balance`: Account's balance at the specified block.
68+
* `nonce`: Account's nonce at the specified block.
69+
* `storageHash`: Hash of the storage root.
70+
* `storageProof`: Array of `StorageProof` objects for each requested storage key.

0 commit comments

Comments
 (0)