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

fix(zk_toolbox): Add chain id for local wallet #2041

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions zk_toolbox/crates/common/src/ethereum.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{ops::Add, time::Duration};

use ethers::prelude::Signer;
use ethers::{
core::k256::ecdsa::SigningKey,
middleware::MiddlewareBuilder,
Expand All @@ -14,8 +15,12 @@ use crate::wallets::Wallet;
pub fn create_ethers_client(
private_key: H256,
l1_rpc: String,
chain_id: Option<u32>,
) -> anyhow::Result<SignerMiddleware<Provider<Http>, ethers::prelude::Wallet<SigningKey>>> {
let wallet = LocalWallet::from_bytes(private_key.as_bytes())?;
let mut wallet = LocalWallet::from_bytes(private_key.as_bytes())?;
if let Some(chain_id) = chain_id {
wallet = wallet.with_chain_id(chain_id);
}
let client = Provider::<Http>::try_from(l1_rpc)?.with_signer(wallet);
Ok(client)
}
Expand All @@ -27,7 +32,7 @@ pub async fn distribute_eth(
chain_id: u32,
amount: u128,
) -> anyhow::Result<()> {
let client = create_ethers_client(main_wallet.private_key.unwrap(), l1_rpc)?;
let client = create_ethers_client(main_wallet.private_key.unwrap(), l1_rpc, Some(chain_id))?;
let mut pending_txs = vec![];
let mut nonce = client.get_transaction_count(client.address(), None).await?;
for address in addresses {
Expand Down
2 changes: 1 addition & 1 deletion zk_toolbox/crates/common/src/forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl ForgeScript {
let Some(private_key) = self.private_key() else {
return Ok(true);
};
let client = create_ethers_client(private_key, rpc_url)?;
let client = create_ethers_client(private_key, rpc_url, None)?;
let balance = client.get_balance(client.address(), None).await?;
Ok(balance > minimum_value)
}
Expand Down
Loading