Skip to content

Commit

Permalink
Merge pull request #123 from lambdaclass/properly-format-readme
Browse files Browse the repository at this point in the history
Properly format readme
  • Loading branch information
fkrause98 authored Oct 3, 2023
2 parents 9e83f8b + 30f44ad commit 2da644f
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ 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;
```
#### Connecting to the zkSync Network
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();
```
Expand All @@ -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<SigningKey> = "0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110".parse().unwrap();
let zksync_era_chain_id: u64 = 270;
let wallet = Wallet::with_chain_id(private_key, zksync_era_chain_id);
Expand All @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 2da644f

Please sign in to comment.