diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea7a7e10..b6c303c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -214,9 +214,18 @@ jobs: - uses: Swatinem/rust-cache@v1 with: cache-on-failure: true + - name: Build all examples + run: | + export PATH=$HOME/bin:$PATH + for file in examples/*.rs; do + name="$(echo "$file" | cut -f 1 -d '.')" + echo "building $name" + cargo build -p ethers --example "$(basename "$name")" + done - name: Run all examples run: | export PATH=$HOME/bin:$PATH + chmod +x ./scripts/examples.sh ./scripts/examples.sh windows-build: diff --git a/examples/contract_human_readable.rs b/examples/contract_human_readable.rs index a4315a7c..67a064a4 100644 --- a/examples/contract_human_readable.rs +++ b/examples/contract_human_readable.rs @@ -31,7 +31,7 @@ async fn main() -> Result<()> { // compile the project and get the artifacts let output = project.compile().unwrap(); let contract = output.find("SimpleStorage").expect("could not find contract").clone(); - let (abi, bytecode, _) = contract.into_parts_or_default(); + let (abi, bytecode, _) = contract.into_parts(); // 2. instantiate our wallet & ganache let ganache = Ganache::new().spawn(); @@ -46,7 +46,7 @@ async fn main() -> Result<()> { let client = Arc::new(client); // 5. create a factory which will be used to deploy instances of the contract - let factory = ContractFactory::new(abi, bytecode, client.clone()); + let factory = ContractFactory::new(abi.unwrap(), bytecode.unwrap(), client.clone()); // 6. deploy it with the constructor arguments let contract = factory.deploy("initial value".to_string())?.legacy().send().await?; diff --git a/examples/moonbeam_with_abi.rs b/examples/moonbeam_with_abi.rs index 266c56c9..3b63af58 100644 --- a/examples/moonbeam_with_abi.rs +++ b/examples/moonbeam_with_abi.rs @@ -1,6 +1,4 @@ use ethers::prelude::*; -use eyre::Result; -use std::{convert::TryFrom, path::Path, sync::Arc, time::Duration}; abigen!( SimpleContract, @@ -8,8 +6,6 @@ abigen!( event_derives(serde::Deserialize, serde::Serialize) ); -const MOONBEAM_DEV_ENDPOINT: &str = "http://localhost:9933"; - /// This requires a running moonbeam dev instance on `localhost:9933` /// See `https://docs.moonbeam.network/builders/get-started/moonbeam-dev/` for reference /// @@ -22,7 +18,10 @@ const MOONBEAM_DEV_ENDPOINT: &str = "http://localhost:9933"; /// Also requires the `legacy` feature to send Legacy transaction instead of an EIP-1559 #[tokio::main] #[cfg(feature = "legacy")] -async fn main() -> Result<()> { +async fn main() -> eyre::Result<()> { + use std::{convert::TryFrom, path::Path, sync::Arc, time::Duration}; + const MOONBEAM_DEV_ENDPOINT: &str = "http://localhost:9933"; + // set the path to the contract, `CARGO_MANIFEST_DIR` points to the directory containing the // manifest of `ethers`. which will be `../` relative to this file let source = Path::new(&env!("CARGO_MANIFEST_DIR")).join("examples/contract.sol"); diff --git a/scripts/examples.sh b/scripts/examples.sh index 8f2d3038..517c3cb7 100755 --- a/scripts/examples.sh +++ b/scripts/examples.sh @@ -1,3 +1,4 @@ +set -e # shellcheck shell=bash # run all examples for file in examples/*.rs; do