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

WIP: feat(general) use gas estimation layer #20

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions examples/anvil/examples/deploy_contract_anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async fn main() -> Result<()> {

let contract = Counter::new(contract_address, &provider);

// Set the number to 42.
let estimate = contract.setNumber(U256::from(42)).estimate_gas().await?;
let builder = contract.setNumber(U256::from(42)).nonce(1).gas(estimate).gas_price(base_fee);
let receipt = builder.send().await?.get_receipt().await?;
Expand Down
3 changes: 2 additions & 1 deletion examples/contracts/examples/deploy_from_artifact.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Example of deploying a contract from an artifact to Anvil and interacting with it.
//! Example of deploying a contract from Solidity code to Anvil and interacting with it.

use alloy::{
network::EthereumSigner,
Expand Down Expand Up @@ -48,6 +48,7 @@ async fn main() -> Result<()> {

let contract = Counter::new(contract_address, &provider);

// Set the number to 42.
let estimate = contract.setNumber(U256::from(42)).estimate_gas().await?;
let builder = contract.setNumber(U256::from(42)).nonce(1).gas(estimate).gas_price(base_fee);
let receipt = builder.send().await?.get_receipt().await?;
Expand Down
1 change: 1 addition & 0 deletions examples/contracts/examples/deploy_from_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async fn main() -> Result<()> {

let contract = Counter::new(contract_address, &provider);

// Set the number to 42.
let estimate = contract.setNumber(U256::from(42)).estimate_gas().await?;
let builder = contract.setNumber(U256::from(42)).nonce(1).gas(estimate).gas_price(base_fee);
let receipt = builder.send().await?.get_receipt().await?;
Expand Down
6 changes: 5 additions & 1 deletion examples/layers/examples/nonce_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use alloy::{
network::{EthereumSigner, TransactionBuilder},
node_bindings::Anvil,
primitives::{address, U256},
providers::{layers::ManagedNonceLayer, Provider, ProviderBuilder},
providers::{
layers::{GasEstimatorLayer, ManagedNonceLayer},
Provider, ProviderBuilder,
},
rpc::{client::RpcClient, types::eth::request::TransactionRequest},
signers::wallet::LocalWallet,
};
Expand Down Expand Up @@ -36,6 +39,7 @@ async fn main() -> Result<()> {
// It is generally recommended to use the `.with_recommended_layers()` method, which
// includes the `ManagedNonceLayer`.
.layer(ManagedNonceLayer)
.layer(GasEstimatorLayer)
.signer(EthereumSigner::from(wallet))
.on_client(RpcClient::new_http(http));

Expand Down
Loading