You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library supports the blob transaction type introduced with [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844).
197
+
Additionally it is able to process blobs in the "PeerDAS way" - introduced with [EIP-7594](https://eips.ethereum.org/EIPS/eip-7594) along the
198
+
`osaka` hardfork and generate cell proofs instead of blob proofs.
194
199
195
200
**Note:** This functionality needs a manual KZG library installation and global initialization, see [KZG Setup](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/tx/README.md#kzg-setup) for instructions.
196
201
197
-
See the following code snippet for an example on how to instantiate:
202
+
#### Example
203
+
204
+
See the following code snippet for an example on how to create a blob transaction, one for EIP-4844 only
205
+
and one taking EIP-7594 into the mix:
198
206
199
207
```ts
200
208
// ./examples/blobTx.ts
@@ -208,15 +216,46 @@ import { KZG as microEthKZG } from 'micro-eth-signer/kzg.js'
208
216
209
217
const main =async () => {
210
218
const kzg =newmicroEthKZG(trustedSetup)
211
-
const common =newCommon({
219
+
// EIP-4844 only
220
+
const common4844 =newCommon({
212
221
chain: Mainnet,
213
222
hardfork: Hardfork.Cancun,
214
223
customCrypto: { kzg },
215
224
})
216
225
226
+
// EIP-4844 and EIP-7594
227
+
const common4844and7594 =newCommon({
228
+
chain: Mainnet,
229
+
hardfork: Hardfork.Osaka,
230
+
customCrypto: { kzg },
231
+
})
232
+
const setups = [
233
+
{
234
+
title: 'Blob transaction (EIP-4844 only)',
235
+
common: common4844,
236
+
proofAmountComment: 'one proof per blob'
237
+
},
238
+
{
239
+
title: 'Blob transaction (EIP-4844 + EIP-7594)',
240
+
common: common4844and7594,
241
+
proofAmountComment: '128 cells per blob + one proof per cell -> NUM_BLOBS * 128 proofs'
// myRPCClient.request('eth_sendRawTransaction', [rawTx]) // submits a transaction via RPC
287
+
//
288
+
// Also see ./sendRawSepoliaTx.ts example
244
289
}
245
290
246
291
voidmain()
@@ -249,15 +294,19 @@ void main()
249
294
250
295
**Note:**`versionedHashes` and `kzgCommitments` have a real length of 32 bytes, `blobs` have a real length of `4096` bytes and values are trimmed here for brevity.
251
296
252
-
You can either pass in blobs as the initial `blobsData` - and the final `blobs` format will be derived for you - or you can pass in the final `blobs` format directly as bytes. `versionedHashes`, `kzgCommitments` and `kzgProofs` are either derived or taken from the values passed in.
297
+
You can either pass in blobs as the initial `blobsData` (the data you want to store in the blob) - and the final `blobs` format (filled with a lot of 0s, added marker) will be derived for you - or you can pass in the final `blobs` format directly as bytes. `versionedHashes`, `kzgCommitments` and `kzgProofs` are either derived or taken from the values passed in.
298
+
299
+
The `kzgProofs` field is used for both blob proofs (EIP-4844) and cell proofs (EIP-7594). Note that the amount of proofs increases by a factor of 128 when EIP-7594 is activated, since proofs are then computed per cell instead of per blob (128 cells per blob).
253
300
254
301
For manually deriving commitments, proofs and versioned hashes, there are dedicated helpers available in the [@ethereumjs/util](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/util) package.
255
302
256
303
#### Serialization
257
304
258
305
Blob transactions can be serialized in two ways.
259
306
1)`tx.serialize()` - the standard serialization returns an RLP-encoded `Uint8Array` that conforms to the transaction as represented after it is included in a block
260
-
2)`tx.serializeNetworkWrapper()` - this serialization format includes the `blobs` in the encoded data and is the format specified for transactions that are being submitted to/gossipped around the mempool. If you are constructing a transaction to submit via JSON-RPC, use this format.
307
+
2)`tx.serializeNetworkWrapper()` - this serialization format includes the `blobs` in the encoded data and is the format specified for transactions that are being submitted to/gossipped around the mempool. **If you are constructing a transaction to submit via JSON-RPC, use this format.**
308
+
309
+
See the [Send Raw Sepolia Tx](./examples/sendRawSepoliaTx.ts) example for a detailed example on how to send a blob transaction via JSON-RPC.
261
310
262
311
See the [Blob Transaction Tests](./test/eip4844.spec.ts) for additional examples of usage in instantiating, serializing, and deserializing these transactions.
0 commit comments