1
- use alloy_consensus:: { SidecarBuilder , SimpleCoder } ;
1
+ use alloy_consensus:: { SidecarBuilder , SignableTransaction , SimpleCoder } ;
2
2
use alloy_dyn_abi:: ErrorExt ;
3
3
use alloy_json_abi:: Function ;
4
4
use alloy_network:: {
5
- AnyNetwork , TransactionBuilder , TransactionBuilder4844 , TransactionBuilder7702 ,
5
+ AnyNetwork , AnyTypedTransaction , TransactionBuilder , TransactionBuilder4844 ,
6
+ TransactionBuilder7702 ,
6
7
} ;
7
8
use alloy_primitives:: { hex, Address , Bytes , TxKind , U256 } ;
8
9
use alloy_provider:: Provider ;
@@ -277,7 +278,7 @@ impl<P: Provider<AnyNetwork>> CastTxBuilder<P, InputState> {
277
278
self ,
278
279
sender : impl Into < SenderKind < ' _ > > ,
279
280
) -> Result < ( WithOtherFields < TransactionRequest > , Option < Function > ) > {
280
- self . _build ( sender, true ) . await
281
+ self . _build ( sender, true , false ) . await
281
282
}
282
283
283
284
/// Builds [TransactionRequest] without filling missing fields. Used for read-only calls such as
@@ -286,13 +287,26 @@ impl<P: Provider<AnyNetwork>> CastTxBuilder<P, InputState> {
286
287
self ,
287
288
sender : impl Into < SenderKind < ' _ > > ,
288
289
) -> Result < ( WithOtherFields < TransactionRequest > , Option < Function > ) > {
289
- self . _build ( sender, false ) . await
290
+ self . _build ( sender, false , false ) . await
291
+ }
292
+
293
+ /// Builds an unsigned RLP-encoded raw transaction.
294
+ ///
295
+ /// Returns the hex encoded string representation of the transaction.
296
+ pub async fn build_unsigned_raw ( self , from : Address ) -> Result < String > {
297
+ let ( tx, _) = self . _build ( SenderKind :: Address ( from) , true , true ) . await ?;
298
+ let tx = tx. build_unsigned ( ) ?;
299
+ match tx {
300
+ AnyTypedTransaction :: Ethereum ( t) => Ok ( hex:: encode_prefixed ( t. encoded_for_signing ( ) ) ) ,
301
+ _ => eyre:: bail!( "Cannot generate unsigned transaction for non-Ethereum transactions" ) ,
302
+ }
290
303
}
291
304
292
305
async fn _build (
293
306
mut self ,
294
307
sender : impl Into < SenderKind < ' _ > > ,
295
308
fill : bool ,
309
+ unsigned : bool ,
296
310
) -> Result < ( WithOtherFields < TransactionRequest > , Option < Function > ) > {
297
311
let sender = sender. into ( ) ;
298
312
let from = sender. address ( ) ;
@@ -316,7 +330,17 @@ impl<P: Provider<AnyNetwork>> CastTxBuilder<P, InputState> {
316
330
nonce
317
331
} ;
318
332
319
- self . resolve_auth ( sender, tx_nonce) . await ?;
333
+ if !unsigned {
334
+ self . resolve_auth ( sender, tx_nonce) . await ?;
335
+ } else if self . auth . is_some ( ) {
336
+ let Some ( CliAuthorizationList :: Signed ( signed_auth) ) = self . auth . take ( ) else {
337
+ eyre:: bail!(
338
+ "SignedAuthorization needs to be provided for generating unsigned 7702 txs"
339
+ )
340
+ } ;
341
+
342
+ self . tx . set_authorization_list ( vec ! [ signed_auth] ) ;
343
+ }
320
344
321
345
if let Some ( access_list) = match self . access_list . take ( ) {
322
346
None => None ,
0 commit comments