Skip to content

Commit

Permalink
chore: make some code more idiomatic (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Jul 31, 2024
1 parent 5b6ceb6 commit 3f66e65
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions examples/contracts/examples/interact_with_abi.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Example of generating code from ABI file using the `sol!` macro to interact with the contract.

use alloy::{node_bindings::Anvil, providers::ProviderBuilder, sol};
use alloy::{node_bindings::Anvil, primitives::address, providers::ProviderBuilder, sol};
use eyre::Result;

// Codegen from ABI file to interact with the contract.
Expand All @@ -22,12 +22,12 @@ async fn main() -> Result<()> {
let provider = ProviderBuilder::new().on_http(rpc_url);

// Create a contract instance.
let contract = IWETH9::new("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2".parse()?, provider);
let contract = IWETH9::new(address!("C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"), provider);

// Call the contract, retrieve the total supply.
let IWETH9::totalSupplyReturn { _0 } = contract.totalSupply().call().await?;
let total_supply = contract.totalSupply().call().await?._0;

println!("WETH total supply is {_0}");
println!("WETH total supply is {total_supply}");

Ok(())
}
4 changes: 2 additions & 2 deletions examples/sol-macro/examples/user_defined_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sol! {
}

// Type aliases
type B32 = sol! { bytes32 };
type Bytes32 = sol! { bytes32 };

// This is equivalent to the following:
// type B32 = alloy_sol_types::sol_data::FixedBytes<32>;
Expand All @@ -24,7 +24,7 @@ type CustomArrayOf<T> = sol! { T[] };
type CustomTuple = sol! { tuple(address, bytes, string) };

fn main() -> Result<()> {
let _b32_type = B32::abi_encode(&[0; 32]);
let _b32_type = Bytes32::abi_encode(&[0; 32]);

let _custom_type = CustomType(U256::from(1));

Expand Down
4 changes: 2 additions & 2 deletions examples/transactions/examples/with_access_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ async fn main() -> Result<()> {
println!("Transaction hash: {tx_hash}");

// Check the value of the contract.
let value = contract.getValue().call().await?;
let value = contract.getValue().call().await?._0;

assert_eq!(value._0, "hello".to_string());
assert_eq!(value, "hello");

Ok(())
}

0 comments on commit 3f66e65

Please sign in to comment.