diff --git a/cast/src/lib.rs b/cast/src/lib.rs index a5634e030827d..87cf2f950a549 100644 --- a/cast/src/lib.rs +++ b/cast/src/lib.rs @@ -7,7 +7,7 @@ use ethers_core::{ token::{LenientTokenizer, Tokenizer}, Abi, AbiParser, Token, }, - types::{Chain, *}, + types::{transaction::eip2718::TypedTransaction, Chain, *}, utils::{self, keccak256}, }; @@ -216,7 +216,7 @@ where args: Option<(&str, Vec)>, chain: Chain, etherscan_api_key: Option, - ) -> Result<(Eip1559TransactionRequest, Option)> { + ) -> Result<(TypedTransaction, Option)> { let from = match from.into() { NameOrAddress::Name(ref ens_name) => self.provider.resolve_name(ens_name).await?, NameOrAddress::Address(addr) => addr, @@ -231,7 +231,11 @@ where }; // make the call - let mut tx = Eip1559TransactionRequest::new().from(from).to(to); + let mut tx: TypedTransaction = if is_legacy(chain) { + TransactionRequest::new().from(from).to(to).into() + } else { + Eip1559TransactionRequest::new().from(from).to(to).into() + }; let func = if let Some((sig, args)) = args { let func = if sig.contains('(') { @@ -247,7 +251,7 @@ where .await? }; let data = encode_args(&func, &args)?; - tx = tx.data(data); + tx.set_data(data.into()); Some(func) } else { None @@ -1042,3 +1046,16 @@ mod tests { ); } } + +/// Helper function for checking if a chainid corresponds to a legacy chainid +/// without eip1559 +fn is_legacy>(chain: T) -> bool { + let chain = match chain.try_into() { + Ok(inner) => inner, + _ => return false, + }; + + use Chain::*; + // TODO: Add other chains which do not support EIP1559. + matches!(chain, Optimism | OptimismKovan | Fantom | FantomTestnet) +} diff --git a/cli/src/opts/mod.rs b/cli/src/opts/mod.rs index aa9d43ef041c0..ca7a76b6f91cd 100644 --- a/cli/src/opts/mod.rs +++ b/cli/src/opts/mod.rs @@ -72,6 +72,7 @@ pub struct EthereumOpts { #[clap(long, env = "ETHERSCAN_API_KEY")] pub etherscan_api_key: Option, + #[clap(long, env = "CHAIN", default_value = "mainnet")] pub chain: Chain, }