Skip to content

Commit

Permalink
fix(zk_toolbox): Add chain id for local wallet (#2041)
Browse files Browse the repository at this point in the history
## What ❔

<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.

Signed-off-by: Danil <deniallugo@gmail.com>
  • Loading branch information
Deniallugo authored May 24, 2024
1 parent 27a26cb commit 8e147c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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

0 comments on commit 8e147c1

Please sign in to comment.