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

feat: add template for smart contract deployment and interaction #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
members = ["app", "crates/bindings"]

[workspace.dependencies]
foundry-contracts = { path = "crates/bindings" }
bindings = { path = "crates/bindings" }
2 changes: 1 addition & 1 deletion app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
foundry-contracts.workspace = true
bindings.workspace = true
eyre = "0.6"
tokio = { version = "1.19", features = ["macros", "rt-multi-thread"] }
alloy = { git = "https://github.com/alloy-rs/alloy", features = [
Expand Down
26 changes: 19 additions & 7 deletions app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
use alloy::{
primitives::Address,
providers::{builder, Provider},
primitives::U256,
providers::builder,
};
use eyre::Result;
use foundry_contracts::counter::Counter;
use bindings::counter::Counter;

#[tokio::main]
async fn main() -> Result<()> {
let provider = builder().with_recommended_fillers().on_anvil_with_wallet();

let address = "0x0000000000000000000000000000000000000000".parse::<Address>()?;
let deployed_contract = Counter::deploy(provider.clone()).await?;
println!("Deployed contract at address: {:?}", deployed_contract.address());

let _contract = Counter::new(address, provider.clone());
let initial_number = deployed_contract.number().call().await?;
println!("Initial number: {}", initial_number._0);

let blk = provider.get_block_number().await?;
println!("Hello, world! {}", blk);
let new_number = U256::from(123);
let set_number_tx = deployed_contract.setNumber(new_number).send().await?;
println!("setNumber called, transaction hash: {:?}", set_number_tx.tx_hash());

let updated_number = deployed_contract.number().call().await?;
println!("Updated number after setting: {}", updated_number._0);

let increment_tx = deployed_contract.increment().send().await?;
println!("increment called, transaction hash: {:?}", increment_tx.tx_hash());

let incremented_number = deployed_contract.number().call().await?;
println!("Number after incrementing: {}", incremented_number._0);
Ok(())
}
2 changes: 1 addition & 1 deletion crates/bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "foundry-contracts"
name = "bindings"
version = "0.1.0"
edition = "2021"

Expand Down