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).
196
+
Additionally it is able to process blobs in the "PeerDAS way" - introduced with [EIP-7594](https://eips.ethereum.org/EIPS/eip-7594) along the
197
+
`osaka` hardfork and generate cell proofs instead of blob proofs.
194
198
195
199
**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
200
197
-
See the following code snippet for an example on how to instantiate:
201
+
#### Example
202
+
203
+
See the following code snippet for an example on how to create a blob transaction, one for EIP-4844 only
204
+
and one taking EIP-7594 into the mix:
198
205
199
206
```ts
200
207
// ./examples/blobTx.ts
@@ -208,15 +215,46 @@ import { KZG as microEthKZG } from 'micro-eth-signer/kzg.js'
208
215
209
216
const main =async () => {
210
217
const kzg =newmicroEthKZG(trustedSetup)
211
-
const common =newCommon({
218
+
// EIP-4844 only
219
+
const common4844 =newCommon({
212
220
chain: Mainnet,
213
221
hardfork: Hardfork.Cancun,
214
222
customCrypto: { kzg },
215
223
})
216
224
225
+
// EIP-4844 and EIP-7594
226
+
const common4844and7594 =newCommon({
227
+
chain: Mainnet,
228
+
hardfork: Hardfork.Osaka,
229
+
customCrypto: { kzg },
230
+
})
231
+
const setups = [
232
+
{
233
+
title: 'Blob transaction (EIP-4844 only)',
234
+
common: common4844,
235
+
proofAmountComment: 'one proof per blob'
236
+
},
237
+
{
238
+
title: 'Blob transaction (EIP-4844 + EIP-7594)',
239
+
common: common4844and7594,
240
+
proofAmountComment: '128 cells per blob + one proof per cell -> NUM_BLOBS * 128 proofs'
// myRPCClient.request('eth_sendRawTransaction', [rawTx]) // submits a transaction via RPC
286
+
//
287
+
// Also see ./sendRawSepoliaTx.ts example
244
288
}
245
289
246
290
voidmain()
@@ -249,15 +293,19 @@ void main()
249
293
250
294
**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
295
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.
296
+
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.
297
+
298
+
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
299
254
300
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
301
256
302
#### Serialization
257
303
258
304
Blob transactions can be serialized in two ways.
259
305
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.
306
+
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
+
308
+
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
309
262
310
See the [Blob Transaction Tests](./test/eip4844.spec.ts) for additional examples of usage in instantiating, serializing, and deserializing these transactions.
0 commit comments