@@ -2,6 +2,7 @@ use crate::tx::{self, CastTxBuilder};
2
2
use alloy_ens:: NameOrAddress ;
3
3
use alloy_network:: { eip2718:: Encodable2718 , EthereumWallet , TransactionBuilder } ;
4
4
use alloy_primitives:: hex;
5
+ use alloy_provider:: Provider ;
5
6
use alloy_signer:: Signer ;
6
7
use clap:: Parser ;
7
8
use eyre:: { OptionExt , Result } ;
@@ -50,6 +51,10 @@ pub struct MakeTxArgs {
50
51
/// Relaxes the wallet requirement.
51
52
#[ arg( long, requires = "from" ) ]
52
53
raw_unsigned : bool ,
54
+
55
+ /// Call `eth_signTransaction` using the `--from` argument or $ETH_FROM as sender
56
+ #[ arg( long, requires = "from" , conflicts_with = "raw_unsigned" ) ]
57
+ ethsign : bool ,
53
58
}
54
59
55
60
#[ derive( Debug , Parser ) ]
@@ -70,7 +75,7 @@ pub enum MakeTxSubcommands {
70
75
71
76
impl MakeTxArgs {
72
77
pub async fn run ( self ) -> Result < ( ) > {
73
- let Self { to, mut sig, mut args, command, tx, path, eth, raw_unsigned } = self ;
78
+ let Self { to, mut sig, mut args, command, tx, path, eth, raw_unsigned, ethsign } = self ;
74
79
75
80
let blob_data = if let Some ( path) = path { Some ( std:: fs:: read ( path) ?) } else { None } ;
76
81
@@ -91,7 +96,7 @@ impl MakeTxArgs {
91
96
92
97
let provider = get_provider ( & config) ?;
93
98
94
- let tx_builder = CastTxBuilder :: new ( provider, tx, & config)
99
+ let tx_builder = CastTxBuilder :: new ( & provider, tx, & config)
95
100
. await ?
96
101
. with_to ( to)
97
102
. await ?
@@ -108,19 +113,30 @@ impl MakeTxArgs {
108
113
return Ok ( ( ) ) ;
109
114
}
110
115
111
- // Retrieve the signer, and bail if it can't be constructed.
112
- let signer = eth. wallet . signer ( ) . await ?;
113
- let from = signer. address ( ) ;
116
+ // Case 1:
117
+ // Use eth_signTransaction to sign the transaction.
118
+ if ethsign {
119
+ let ( tx, _) = tx_builder. build ( config. sender ) . await ?;
120
+
121
+ let signed_tx = provider. sign_transaction ( tx) . await ?;
122
+ sh_println ! ( "{signed_tx}" ) ?;
114
123
115
- tx:: validate_from_address ( eth. wallet . from , from) ?;
124
+ // Case 2:
125
+ // local signer
126
+ } else {
127
+ // get the signer from the wallet, and fail if it can't be constructed.
128
+ let signer = eth. wallet . signer ( ) . await ?;
129
+ let from = signer. address ( ) ;
116
130
117
- let ( tx , _ ) = tx_builder . build ( & signer ) . await ?;
131
+ tx :: validate_from_address ( eth . wallet . from , from ) ?;
118
132
119
- let tx = tx . build ( & EthereumWallet :: new ( signer) ) . await ?;
133
+ let ( tx , _ ) = tx_builder . build ( & signer) . await ?;
120
134
121
- let signed_tx = hex:: encode ( tx. encoded_2718 ( ) ) ;
122
- sh_println ! ( "0x{signed_tx}" ) ?;
135
+ let tx = tx. build ( & EthereumWallet :: new ( signer) ) . await ?;
123
136
137
+ let signed_tx = hex:: encode ( tx. encoded_2718 ( ) ) ;
138
+ sh_println ! ( "0x{signed_tx}" ) ?;
139
+ }
124
140
Ok ( ( ) )
125
141
}
126
142
}
0 commit comments