Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cast): switch chain before sending tx if current chain is different #5077

Merged
merged 2 commits into from
Jun 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cli/src/cmd/cast/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ impl SendTxArgs {
// This should be the only way this RPC method is used as it requires a local node
// or remote RPC with unlocked accounts.
if unlocked {
// only check current chain id if it was specified in the config
if let Some(config_chain) = config.chain_id {
let current_chain_id = provider.get_chainid().await?.as_u64();
let config_chain_id = config_chain.id();
// switch chain if current chain id is not the same as the one specified in the config
if config_chain_id != current_chain_id {
provider
.request(
"wallet_switchEthereumChain",
[serde_json::json!({
"chainId": format!("0x{:x}", config_chain_id),
})],
)
.await?;
}
}

if resend {
tx.nonce = Some(provider.get_transaction_count(config.sender, None).await?);
}
Expand Down