Sitelet https://github.com/SharkHand3/examples/commit/04d4367076ff2e291ef48b6d04da36d27966acaa
Skip to content

Commit 04d4367

Browse files
decofemattsse
andauthored
chore: migrate to alloy 2.0 (alloy-rs#246)
* chore: migrate to alloy 2.0, revm 37, foundry-fork-db 0.25, alloy-evm 0.32 Co-Authored-By: Matthias Seitz <19890894+mattsse@users.noreply.github.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d956b-3440-72b2-9776-163c2e9c77c0 * style: fix nightly rustfmt formatting Co-Authored-By: Matthias Seitz <19890894+mattsse@users.noreply.github.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d956b-3440-72b2-9776-163c2e9c77c0 --------- Co-authored-by: Matthias Seitz <19890894+mattsse@users.noreply.github.com>
1 parent 8d53b58 commit 04d4367

7 files changed

Lines changed: 34 additions & 33 deletions

File tree

‎Cargo.toml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ significant_drop_tightening = "allow"
9595
needless_return = "allow"
9696

9797
[workspace.dependencies]
98-
alloy = { version = "1.1.0", features = [
98+
alloy = { version = "2.0.0", features = [
9999
"eips",
100100
"ens",
101101
"full",
@@ -140,11 +140,11 @@ http-body-util = "0.1"
140140
tracing-subscriber = "0.3"
141141
aws-config = { version = "1.8", default-features = false }
142142
aws-sdk-kms = { version = "1.77", default-features = false }
143-
gcloud-sdk = "0.27"
143+
gcloud-sdk = { version = "0.29", default-features = false }
144144
tempfile = "3.23"
145-
foundry-fork-db = "0.19"
146-
alloy-evm = "0.22"
147-
revm = { version = "30", default-features = false }
145+
foundry-fork-db = "0.25"
146+
alloy-evm = "0.32"
147+
revm = { version = "37", default-features = false }
148148
ethabi = "18"
149149
rlp = "0.6.1"
150150
rlp-derive = "0.2.0"

‎examples/advanced/examples/any_network.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async fn main() -> Result<()> {
5959
let receipt = builder.send().await?.get_receipt().await?;
6060

6161
// Fetch the `gasUsedForL1` and `l1BlockNumber` fields from the receipt.
62-
let arb_fields: ArbOtherFields = receipt.other.deserialize_into()?;
62+
let arb_fields: ArbOtherFields = receipt.deserialize_other()?;
6363
let l1_gas = arb_fields.gas_used_for_l1.to::<u128>();
6464
let l1_block_number = arb_fields.l1_block_number.to::<u64>();
6565

‎examples/advanced/examples/foundry_fork_db.rs‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async fn main() -> Result<()> {
4040

4141
// The `BlockchainDbMeta` is used a identifier when the db is flushed to the disk.
4242
// This aids in cases where the disk contains data from multiple forks.
43-
let meta = BlockchainDbMeta::default().with_block(&block.inner).with_url(&anvil.endpoint());
43+
let meta = BlockchainDbMeta::default().with_url(&anvil.endpoint());
4444

4545
let db = BlockchainDb::new(meta, None);
4646

@@ -102,7 +102,7 @@ async fn main() -> Result<()> {
102102

103103
let res = evm.transact(configure_tx_env(tx_req)).unwrap();
104104

105-
let total_spent = U256::from(res.result.gas_used()) * U256::from(basefee) + U256::from(100);
105+
let total_spent = U256::from(res.result.tx_gas_used()) * U256::from(basefee) + U256::from(100);
106106

107107
shared.data().do_commit(res.state);
108108

@@ -138,12 +138,17 @@ fn configure_evm(
138138
block.header.excess_blob_gas().unwrap_or_default(),
139139
SpecId::PRAGUE,
140140
)),
141+
slot_num: 0,
141142
};
142143

143144
let context = EthEvmContext::new(WrapDatabaseRef(shared), SpecId::PRAGUE).with_block(block_env);
144145

145-
let evm = RevmEvm::new(context, EthInstructions::default(), EthPrecompiles::default())
146-
.with_inspector(NoOpInspector);
146+
let evm = RevmEvm::new(
147+
context,
148+
EthInstructions::new_mainnet_with_spec(SpecId::PRAGUE),
149+
EthPrecompiles::new(SpecId::PRAGUE),
150+
)
151+
.with_inspector(NoOpInspector);
147152

148153
EthEvm::new(evm, false)
149154
}

‎examples/transactions/examples/send_eip4844_transaction.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Example showing how to send an [EIP-4844](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4844.md) transaction.
22
33
use alloy::{
4-
consensus::{SidecarBuilder, SimpleCoder},
4+
consensus::{BlobTransactionSidecar, SidecarBuilder, SimpleCoder},
55
eips::eip4844::DATA_GAS_PER_BLOB,
66
network::{TransactionBuilder, TransactionBuilder4844},
77
providers::{Provider, ProviderBuilder},
@@ -23,11 +23,11 @@ async fn main() -> Result<()> {
2323

2424
// Create a sidecar with some data.
2525
let sidecar: SidecarBuilder<SimpleCoder> = SidecarBuilder::from_slice(b"Blobs are fun!");
26-
let sidecar = sidecar.build()?;
26+
let sidecar: BlobTransactionSidecar = sidecar.build()?;
2727

2828
// Build a transaction to send the sidecar from Alice to Bob.
2929
// The `from` field is automatically filled to the first signer's address (Alice).
30-
let tx = TransactionRequest::default().with_to(bob).with_blob_sidecar(sidecar);
30+
let tx = TransactionRequest::default().with_to(bob).with_blob_sidecar(sidecar.into());
3131

3232
// Send the transaction and wait for the broadcast.
3333
let pending_tx = provider.send_transaction(tx).await?;

‎examples/transactions/examples/send_eip7594_transaction.rs‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
33
use alloy::{
44
consensus::{
5-
EnvKzgSettings, EthereumTxEnvelope, SidecarBuilder, SimpleCoder, TxEip4844WithSidecar,
5+
BlobTransactionSidecarVariant, EthereumTxEnvelope, SidecarBuilder, SimpleCoder,
6+
TxEip4844WithSidecar,
67
},
78
eips::{eip7594::BlobTransactionSidecarEip7594, Encodable2718},
89
network::{TransactionBuilder, TransactionBuilder4844},
@@ -23,23 +24,24 @@ async fn main() -> Result<()> {
2324
let alice = accounts[0];
2425
let bob = accounts[1];
2526

26-
// Create a sidecar with some data.
27+
// Create a sidecar with some data and build it directly as an EIP-7594 sidecar.
2728
let sidecar: SidecarBuilder<SimpleCoder> = SidecarBuilder::from_slice(b"Blobs are fun!");
28-
let sidecar = sidecar.build()?;
29+
let sidecar: BlobTransactionSidecarEip7594 = sidecar.build()?;
2930

3031
// Build a transaction to send the sidecar from Alice to Bob.
3132
// The `from` field is automatically filled to the first signer's address (Alice).
32-
let tx = TransactionRequest::default().with_to(bob).with_blob_sidecar(sidecar);
33+
let tx = TransactionRequest::default()
34+
.with_to(bob)
35+
.with_blob_sidecar(BlobTransactionSidecarVariant::Eip7594(sidecar));
3336

3437
// Fill the transaction (e.g., nonce, gas, etc.) using the provider and convert it to an
3538
// envelope.
3639
let envelope = provider.fill(tx).await?.try_into_envelope()?;
3740

38-
// Convert the envelope into an EIP-7594 transaction by converting the sidecar.
39-
let tx: EthereumTxEnvelope<TxEip4844WithSidecar<BlobTransactionSidecarEip7594>> =
40-
envelope.try_into_pooled()?.try_map_eip4844(|tx| {
41-
tx.try_map_sidecar(|sidecar| sidecar.try_into_7594(EnvKzgSettings::Default.get()))
42-
})?;
41+
// Convert the envelope into a pooled transaction with EIP-7594 sidecar.
42+
let tx: EthereumTxEnvelope<TxEip4844WithSidecar<BlobTransactionSidecarEip7594>> = envelope
43+
.try_into_pooled()?
44+
.try_map_eip4844(|tx| tx.try_map_sidecar(|sidecar| sidecar.try_into_eip7594()))?;
4345

4446
let encoded_tx = tx.encoded_2718();
4547

@@ -48,7 +50,7 @@ async fn main() -> Result<()> {
4850

4951
println!("Pending transaction... {}", pending_tx.tx_hash());
5052

51-
// // Wait for the transaction to be included and get the receipt.
53+
// Wait for the transaction to be included and get the receipt.
5254
let receipt = pending_tx.get_receipt().await?;
5355

5456
println!(
@@ -59,13 +61,5 @@ async fn main() -> Result<()> {
5961
assert_eq!(receipt.from, alice);
6062
assert_eq!(receipt.to, Some(bob));
6163

62-
println!(
63-
"Transaction included in block {}",
64-
receipt.block_number.expect("Failed to get block number")
65-
);
66-
67-
assert_eq!(receipt.from, alice);
68-
assert_eq!(receipt.to, Some(bob));
69-
7064
Ok(())
7165
}

‎examples/transactions/examples/send_private_transaction.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! Example of sending a private transaction using Flashbots Protect.
22
33
use alloy::{
4-
network::{eip2718::Encodable2718, EthereumWallet, TransactionBuilder},
4+
network::{
5+
eip2718::Encodable2718, EthereumWallet, NetworkTransactionBuilder, TransactionBuilder,
6+
},
57
primitives::U256,
68
providers::{Provider, ProviderBuilder},
79
rpc::types::TransactionRequest,

‎examples/transactions/examples/send_raw_transaction.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Example of signing, encoding and sending a raw transaction using a wallet.
22
33
use alloy::{
4-
network::TransactionBuilder,
4+
network::{NetworkTransactionBuilder, TransactionBuilder},
55
primitives::U256,
66
providers::{Provider, ProviderBuilder, WalletProvider},
77
rpc::types::TransactionRequest,

0 commit comments

Comments
 (0)