-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from alexdwagner/main
Added docs for getProof, transactionSerializer, and getArgsFromTransactionDepositedOpaqueData.
- Loading branch information
Showing
4 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
site/docs/utilities/deposits/getL2HashFromL1DepositInfo.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
.../docs/utilities/transactionHelpers/getArgsFromTransactionDepositedOpaqueData.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
site/docs/utilities/transactionHelpers/transactionSerializer.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |