diff --git a/README.md b/README.md index 02caebf..9a83376 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ In the following steps, we will show you how to create a payment transaction usi Import the `zksync-web3-rs` library into your project by adding the following line to the top of your `main.rs` file: -```rust,no_run +```rust use zksync_web3_rs as zksync; ``` @@ -68,8 +68,8 @@ use zksync_web3_rs as zksync; To connect to the zkSync network, you need to provide the URL of the zkSync node. The localnet runs both an *Ethereum* node (L1) on port `8545` and an *Era* node (L2) on port `3050`. You can connect to the zkSync Era network using the following code: -```rust,no_run -# use zksync_web3_rs as zksync; +```rust +use zksync_web3_rs as zksync; let provider = zksync::prelude::Provider::try_from("http://localhost:3050").unwrap(); ``` @@ -79,11 +79,11 @@ let provider = zksync::prelude::Provider::try_from("http://localhost:3050").unwr > We set the chain id to 270 because we are using the zkSync Era node. If you want to use the mainnet, you should set the chain id to 9. > https://era.zksync.io/docs/tools/hardhat/testing.html#connect-wallet-to-local-nodes -```rust,no_run -# use zksync_web3_rs as zksync; +```rust +use zksync_web3_rs as zksync; use zksync::signers::{Wallet, Signer}; use zksync::core::k256::ecdsa::SigningKey; -# let provider = zksync_web3_rs::prelude::Provider::try_from("http://localhost:3050").unwrap(); +let provider = zksync_web3_rs::prelude::Provider::try_from("http://localhost:3050").unwrap(); let private_key: Wallet = "0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110".parse().unwrap(); let zksync_era_chain_id: u64 = 270; let wallet = Wallet::with_chain_id(private_key, zksync_era_chain_id); @@ -94,11 +94,12 @@ let zk_wallet = zksync::ZKSWallet::new(wallet, None, Some(provider.clone()), Non To create a payment transaction, you need to provide the sender's address, the receiver's address, and the amount to transfer. You can create a payment transaction using the following code: Notice the await, this code should run inside an async function. ```rust,no_run -# use zksync_web3_rs as zksync; -# use zksync::types::H160; -# let receiver_address: H160 = Default::default(); -# let sender_address: H160 = Default::default(); -# let amount_to_transfer = zksync_web3_rs::types::U256::from(1); +use zksync_web3_rs as zksync; +use zksync::types::Address; +// Use actual addresses here +let receiver_address: Address = "..".parse().unwrap(); +let sender_address: Address = "..".parse().unwrap(); +let amount_to_transfer = zksync_web3_rs::types::U256::from(1); let payment_request = zksync::zks_wallet::TransferRequest::new(amount_to_transfer) .to(receiver_address) .from(sender_address); // Use zk_wallet.l2_address() method to send it from the wallet address. @@ -120,7 +121,9 @@ This will send the transaction to the node and return its ID (hash). To get more ```rust,compile_fail use zksync_web3_rs as zksync; use zksync::prelude::Middleware; -# let provider = zksync::prelude::Provider::try_from("http://localhost:3050").unwrap(); +// Using the local node, keep in mind +// this should be in an async block. +let provider = zksync::prelude::Provider::try_from("http://localhost:3050").unwrap(); let payment_transaction_receipt = provider .get_transaction_receipt(payment_transaction_id) .await