-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contracts): update to
cb95183
and add `with_recommended_filler…
…s()` to examples where appropriate (#50) * upgrade to cd5a2c7 * start updating examples * fix examples * fix clippy and ordering * requires signer and from, not sure why it is not inheriting from the provider * upgrade to cb95183 * fix broken examples * update layer -> singer, add gas_signer and improve documentation
- Loading branch information
1 parent
b7649b5
commit 4d111af
Showing
26 changed files
with
226 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//! Example of using the `.with_recommended_fillers()` method in the provider. | ||
use alloy::{ | ||
network::{EthereumSigner, TransactionBuilder}, | ||
node_bindings::Anvil, | ||
primitives::{address, U256}, | ||
providers::{Provider, ProviderBuilder}, | ||
rpc::types::eth::request::TransactionRequest, | ||
signers::wallet::LocalWallet, | ||
}; | ||
use eyre::Result; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
// Spin up a local Anvil node. | ||
// Ensure `anvil` is available in $PATH. | ||
let anvil = Anvil::new().try_spawn()?; | ||
|
||
// Set up signer from the first default Anvil account (Alice). | ||
let signer: LocalWallet = anvil.keys()[0].clone().into(); | ||
|
||
// Create two users, Alice and Vitalik. | ||
let alice = signer.address(); | ||
let vitalik = address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045"); | ||
|
||
// Create a provider with the signer. | ||
let rpc_url = anvil.endpoint().parse()?; | ||
let provider = ProviderBuilder::new() | ||
// Adds the `ChainIdFiller`, `GasFiller` and the `NonceFiller` layers. | ||
.with_recommended_fillers() | ||
.signer(EthereumSigner::from(signer)) | ||
.on_http(rpc_url)?; | ||
|
||
// Build a EIP-1559 type transaction. | ||
// Notice that the `nonce` field is set by the `NonceFiller`. | ||
// Notice that the gas related fields are set by the `GasFiller`. | ||
// Notice that the `chain_id` field is set by the `ChainIdFiller`. | ||
let tx = TransactionRequest::default() | ||
.with_from(alice) | ||
.with_to(vitalik.into()) | ||
.with_value(U256::from(100)); | ||
|
||
// Send the transaction, the nonce (0) is automatically managed by the provider. | ||
let builder = provider.send_transaction(tx.clone()).await?; | ||
let node_hash = *builder.tx_hash(); | ||
let pending_tx = provider.get_transaction_by_hash(node_hash).await?; | ||
assert_eq!(pending_tx.nonce, 0); | ||
|
||
println!("Transaction sent with nonce: {}", pending_tx.nonce); | ||
|
||
// Send the transaction, the nonce (1) is automatically managed by the provider. | ||
let builder = provider.send_transaction(tx).await?; | ||
let node_hash = *builder.tx_hash(); | ||
let pending_tx = provider.get_transaction_by_hash(node_hash).await?; | ||
assert_eq!(pending_tx.nonce, 1); | ||
|
||
println!("Transaction sent with nonce: {}", pending_tx.nonce); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.