22
33use alloy:: {
44 consensus:: {
5- EnvKzgSettings , EthereumTxEnvelope , SidecarBuilder , SimpleCoder , TxEip4844WithSidecar ,
5+ BlobTransactionSidecarVariant , EthereumTxEnvelope , SidecarBuilder , SimpleCoder ,
6+ TxEip4844WithSidecar ,
67 } ,
78 eips:: { eip7594:: BlobTransactionSidecarEip7594 , Encodable2718 } ,
89 network:: { TransactionBuilder , TransactionBuilder4844 } ,
@@ -23,23 +24,24 @@ async fn main() -> Result<()> {
2324 let alice = accounts[ 0 ] ;
2425 let bob = accounts[ 1 ] ;
2526
26- // Create a sidecar with some data.
27+ // Create a sidecar with some data and build it directly as an EIP-7594 sidecar .
2728 let sidecar: SidecarBuilder < SimpleCoder > = SidecarBuilder :: from_slice ( b"Blobs are fun!" ) ;
28- let sidecar = sidecar. build ( ) ?;
29+ let sidecar: BlobTransactionSidecarEip7594 = sidecar. build ( ) ?;
2930
3031 // Build a transaction to send the sidecar from Alice to Bob.
3132 // The `from` field is automatically filled to the first signer's address (Alice).
32- let tx = TransactionRequest :: default ( ) . with_to ( bob) . with_blob_sidecar ( sidecar) ;
33+ let tx = TransactionRequest :: default ( )
34+ . with_to ( bob)
35+ . with_blob_sidecar ( BlobTransactionSidecarVariant :: Eip7594 ( sidecar) ) ;
3336
3437 // Fill the transaction (e.g., nonce, gas, etc.) using the provider and convert it to an
3538 // envelope.
3639 let envelope = provider. fill ( tx) . await ?. try_into_envelope ( ) ?;
3740
38- // Convert the envelope into an EIP-7594 transaction by converting the sidecar.
39- let tx: EthereumTxEnvelope < TxEip4844WithSidecar < BlobTransactionSidecarEip7594 > > =
40- envelope. try_into_pooled ( ) ?. try_map_eip4844 ( |tx| {
41- tx. try_map_sidecar ( |sidecar| sidecar. try_into_7594 ( EnvKzgSettings :: Default . get ( ) ) )
42- } ) ?;
41+ // Convert the envelope into a pooled transaction with EIP-7594 sidecar.
42+ let tx: EthereumTxEnvelope < TxEip4844WithSidecar < BlobTransactionSidecarEip7594 > > = envelope
43+ . try_into_pooled ( ) ?
44+ . try_map_eip4844 ( |tx| tx. try_map_sidecar ( |sidecar| sidecar. try_into_eip7594 ( ) ) ) ?;
4345
4446 let encoded_tx = tx. encoded_2718 ( ) ;
4547
@@ -48,7 +50,7 @@ async fn main() -> Result<()> {
4850
4951 println ! ( "Pending transaction... {}" , pending_tx. tx_hash( ) ) ;
5052
51- // // Wait for the transaction to be included and get the receipt.
53+ // Wait for the transaction to be included and get the receipt.
5254 let receipt = pending_tx. get_receipt ( ) . await ?;
5355
5456 println ! (
@@ -59,13 +61,5 @@ async fn main() -> Result<()> {
5961 assert_eq ! ( receipt. from, alice) ;
6062 assert_eq ! ( receipt. to, Some ( bob) ) ;
6163
62- println ! (
63- "Transaction included in block {}" ,
64- receipt. block_number. expect( "Failed to get block number" )
65- ) ;
66-
67- assert_eq ! ( receipt. from, alice) ;
68- assert_eq ! ( receipt. to, Some ( bob) ) ;
69-
7064 Ok ( ( ) )
7165}
0 commit comments