Skip to content

Commit

Permalink
fix direct connection to localhost in case of anvil use
Browse files Browse the repository at this point in the history
  • Loading branch information
zerosnacks committed Mar 25, 2024
1 parent 044c179 commit 0d57ec2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ alloy = { git = "https://github.com/alloy-rs/alloy", rev = "fd8f065", features =
"signer-ledger",
"signer-trezor",
"signer-wallet",
# "signer-keystore",
"signer-mnemonic",
"signer-yubihsm",
# "transports",
Expand Down
11 changes: 5 additions & 6 deletions examples/wallets/examples/private_key_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use alloy::{
network::EthereumSigner,
node_bindings::Anvil,
primitives::U256,
primitives::{address, U256},
providers::{Provider, ProviderBuilder},
rpc::{client::RpcClient, types::eth::request::TransactionRequest},
signers::wallet::LocalWallet,
Expand All @@ -16,19 +16,18 @@ async fn main() -> Result<()> {
let anvil = Anvil::new().block_time(1).try_spawn()?;

// Set up the wallets.
let alice: LocalWallet = anvil.keys()[0].clone().into();
let bob: LocalWallet = anvil.keys()[1].clone().into();
let wallet: LocalWallet = anvil.keys()[0].clone().into();

// Create a provider with the signer.
let http = "http://localhost:8545".parse()?;
let http = anvil.endpoint().parse()?;
let provider = ProviderBuilder::new()
.signer(EthereumSigner::from(alice))
.signer(EthereumSigner::from(wallet))
.on_client(RpcClient::new_http(http));

// Create a transaction.
let tx = TransactionRequest {
value: Some(U256::from(100)),
to: Some(bob.address()),
to: address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045").into(),
nonce: Some(0),
gas_price: Some(U256::from(20e9)),
gas: Some(U256::from(21000)),
Expand Down

0 comments on commit 0d57ec2

Please sign in to comment.