diff --git a/core/src/signer.rs b/core/src/signer.rs index 8a313b6..a15ba44 100644 --- a/core/src/signer.rs +++ b/core/src/signer.rs @@ -194,7 +194,7 @@ pub trait AccountSigner { options: Self::SigningOptions, chain_id: u64, address: Address, - nonce: alloy::primitives::U256, + nonce: u64, credentials: &SigningCredential, ) -> impl std::future::Future> + Send; } @@ -355,14 +355,14 @@ impl AccountSigner for EoaSigner { options: EoaSigningOptions, chain_id: u64, address: Address, - nonce: U256, + nonce: u64, credentials: &SigningCredential, ) -> Result { // Create the Authorization struct that both clients expect let authorization = Authorization { chain_id: U256::from(chain_id), address, - nonce: nonce.to::(), + nonce, }; match credentials { SigningCredential::Vault(auth_method) => { diff --git a/executors/src/eip7702_executor/send.rs b/executors/src/eip7702_executor/send.rs index 33499db..4fa9992 100644 --- a/executors/src/eip7702_executor/send.rs +++ b/executors/src/eip7702_executor/send.rs @@ -96,6 +96,13 @@ pub enum Eip7702SendError { inner_error: Option, }, + #[error("Failed to fetch nonce: {message}")] + #[serde(rename_all = "camelCase")] + NonceFetchError { + message: String, + inner_error: Option, + }, + #[error("Failed to call bundler: {message}")] BundlerCallError { message: String }, @@ -264,7 +271,13 @@ where // 5. Sign authorization if needed let authorization = if !is_minimal_account { - let nonce = job_data.nonce.unwrap_or_default(); + let nonce = get_eoa_nonce(&chain, job_data.eoa_address) + .await + .map_err(|e| Eip7702SendError::NonceFetchError { + message: format!("Failed to fetch nonce: {e}"), + inner_error: Some(e), + }) + .map_err_fail()?; let auth = self .eoa_signer @@ -511,3 +524,18 @@ async fn check_is_7702_minimal_account( Ok(is_delegated) } + +async fn get_eoa_nonce(chain: &impl Chain, eoa_address: Address) -> Result { + chain + .provider() + .get_transaction_count(eoa_address) + .await + .map_err(|e| EngineError::RpcError { + chain_id: chain.chain_id(), + rpc_url: chain.rpc_url().to_string(), + message: format!("Failed to get nonce for address {}: {}", eoa_address, e), + kind: RpcErrorKind::InternalError { + message: e.to_string(), + }, + }) +}