{"id":21526894,"url":"https://github.com/lambdaclass/zksync-web3-rs","last_synced_at":"2025-03-22T16:04:40.400Z","repository":{"id":165623084,"uuid":"640036724","full_name":"lambdaclass/zksync-web3-rs","owner":"lambdaclass","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-20T20:23:53.000Z","size":28856,"stargazers_count":32,"open_issues_count":28,"forks_count":16,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-14T18:09:47.012Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lambdaclass.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-12T20:27:55.000Z","updated_at":"2025-01-29T16:07:15.000Z","dependencies_parsed_at":"2024-08-19T19:33:26.988Z","dependency_job_id":"001cbc06-6fcf-4dd4-bc32-917dfbc8f780","html_url":"https://github.com/lambdaclass/zksync-web3-rs","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdaclass%2Fzksync-web3-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdaclass%2Fzksync-web3-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdaclass%2Fzksync-web3-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdaclass%2Fzksync-web3-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lambdaclass","download_url":"https://codeload.github.com/lambdaclass/zksync-web3-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244982041,"owners_count":20542300,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T01:47:02.343Z","updated_at":"2025-03-22T16:04:40.379Z","avatar_url":"https://github.com/lambdaclass.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zksync-web3-rs\n\n## Table of Contents\n\n- [zksync-web3-rs](#zksync-web3-rs)\n  - [Table of Contents](#table-of-contents)\n  - [Getting Started with zkSync Web3 SDK](#getting-started-with-zksync-web3-sdk)\n    - [Prerequisites](#prerequisites)\n    - [Adding dependencies](#adding-dependencies)\n    - [First steps](#first-steps)\n      - [Importing dependencies](#importing-dependencies)\n      - [Connecting to the zkSync Network](#connecting-to-the-zksync-network)\n      - [Creating a ZK-Wallet](#creating-a-zk-wallet)\n      - [Creating a Payment Transaction](#creating-a-payment-transaction)\n      - [Sending the Transaction](#sending-the-transaction)\n      - [Checking zkSync account balance](#checking-zksync-account-balance)\n    - [Simple Transfer Example](#simple-transfer-example)\n      - [Clone the Repository](#clone-the-repository)\n      - [Run a zkSync localnet](#run-a-zksync-localnet)\n      - [Run the Simple Transfer Example](#run-the-simple-transfer-example)\n    - [Conclusion](#conclusion)\n\n## Getting Started with zkSync Web3 SDK\n\nWhile most of the existing SDKs should work out of the box, deploying smart contracts or using unique zkSync features, like account abstraction, requires providing additional fields to those that Ethereum transactions have by default.\n\nTo provide easy access to all of the features of zkSync Era, the `zksync-web3-rs` Rust SDK was created, which is made in a way that has an interface very similar to those of [ethers](https://docs.ethers.io/v5/). In fact, ethers is a peer dependency of our library and most of the objects exported by `zksync-web3-rs` (e.g. `Provider` etc.) inherit from the corresponding `ethers` objects and override only the fields that need to be changed.\n\nThe library is made in such a way that after replacing `ethers` with `zksync-web3-rs` most client apps will work out of box.\n\n### Prerequisites\n\nBefore you begin, make sure you have the following prerequisites:\n\n- Rust: Ensure that Rust is installed on your system. You can install Rust by following the instructions at [https://www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install).\n\n- Git: Install Git on your system if you haven't already. You can find installation instructions at [https://git-scm.com/book/en/v2/Getting-Started-Installing-Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git).\n\n### Adding dependencies\n\nThis crate is published on crates.io, so you can simply do:\n\n```bash\ncargo add zksync-web3-rs\n```\n\nOr, if you want to use the latest changes, add this to your `Cargo.toml` file:\n\n```bash\nzksync-web3-rs = { git = \"https://www.github.com/lambdaclass/zksync-web3-rs\", branch = \"main\"}\n```\n\n\u003e Maybe consider adding tokio as dependency since we are using a lot of async/await functions. If this example is meant to be done in the main function the #[tokio::main] annotation is needed.\n\n### First steps\n\nIn the following steps, we will show you how to create a payment transaction using the `zksync-web3-rs` library.\n\n#### Importing dependencies\n\nImport the `zksync-web3-rs` library into your project by adding the following line to the top of your `main.rs` file:\n\n```rust\nuse zksync_web3_rs as zksync;\n```\n\n#### Connecting to the zkSync Network\n\nTo 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:\n\n```rust\nuse zksync_web3_rs as zksync;\nlet provider = zksync::prelude::Provider::try_from(\"http://localhost:3050\").unwrap();\n```\n\n#### Creating a ZK-Wallet\n\n\n\u003e 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.\n\u003e https://era.zksync.io/docs/tools/hardhat/testing.html#connect-wallet-to-local-nodes\n\n```rust\nuse zksync_web3_rs as zksync;\nuse zksync::signers::{Wallet, Signer};\nuse zksync::core::k256::ecdsa::SigningKey;\nlet provider = zksync_web3_rs::prelude::Provider::try_from(\"http://localhost:3050\").unwrap();\nlet private_key: Wallet\u003cSigningKey\u003e = \"0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110\".parse().unwrap();\nlet zksync_era_chain_id: u64 = 270;\nlet wallet = Wallet::with_chain_id(private_key, zksync_era_chain_id);\nlet zk_wallet = zksync::ZKSWallet::new(wallet, None, Some(provider.clone()), None).unwrap();\n```\n\n#### Creating a Payment Transaction\nTo 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:\nNotice the await, this code should run inside an async function.\n```rust,no_run\nuse zksync_web3_rs as zksync;\nuse zksync::types::Address;\n// Use actual addresses here\nlet receiver_address: Address = \"..\".parse().unwrap();\nlet sender_address: Address = \"..\".parse().unwrap();\nlet amount_to_transfer = zksync_web3_rs::types::U256::from(1);\nlet payment_request = zksync::zks_wallet::TransferRequest::new(amount_to_transfer)\n        .to(receiver_address)\n        .from(sender_address); // Use zk_wallet.l2_address() method to send it from the wallet  address.\n```\n\n#### Sending the Transaction\n\nTo send the payment transaction, you need to use the wallet and the transfer request. You can send the transaction using the following code:\n\n\u003e In case you are wondering, the transaction is signed in the `send_transaction` method inside the transfer process.\n\n```rust,compile_fail\nlet payment_transaction_id =\n        zk_wallet.transfer(\u0026payment_request, None).await.unwrap();\n```\n\nThis will send the transaction to the node and return its ID (hash). To get more information about the transaction we can ask for the `TransactionReceipt` with the following lines:\n\n```rust,compile_fail\nuse zksync_web3_rs as zksync;\nuse zksync::prelude::Middleware;\n// Using the local node, keep in mind \n// this should be in an async block.\nlet provider = zksync::prelude::Provider::try_from(\"http://localhost:3050\").unwrap();\nlet payment_transaction_receipt = provider\n        .get_transaction_receipt(payment_transaction_id)\n        .await\n        .unwrap()\n        .unwrap();\n```\n\n#### Checking zkSync account balance\n```rust,compile_fail\nlet sender_balance = provider\n    .get_balance(sender_address, None)\n    .await\n    .unwrap();\n```\n\n### Simple Transfer Example\n\nThere's an executable example involving the previous steps in the `examples` folder. To run the example, follow the steps below:\n\n#### Clone the Repository\n\nTo get started, clone the `zksync-web3-rs` repository from GitHub. Open a terminal or command prompt and execute the following commands:\n\n```bash\ngit clone https://github.com/lambdaclass/zksync-web3-rs.git\ncd zksync-web3-rs\n```\n\n#### Run a zkSync localnet\n\nTo run the zkSync localnet, clone the `local-setup` repository and execute the following command:\n\n```bash\ngit clone https://github.com/lambdaclass/local-setup\ncd local-setup\ndocker-compose up\n```\n\n#### Run the Simple Transfer Example\n\nTo run the payment transaction example using EIP1559 transactions on zkSync Era, run the following command:\n\n```bash\ncargo run --example simple_payment -- --host \u003cHOST\u003e --port \u003cPORT\u003e --amount \u003cAMOUNT\u003e --from \u003cSENDER_ADDRESS\u003e --to \u003cRECEIVER_ADDRESS\u003e --private-key \u003cPRIVATE_KEY\u003e\n```\n\n- `HOST`: The IP address or hostname of the node.\n- `PORT`: The port number of the node.\n- `AMOUNT`: The amount to transfer.\n- `SENDER_ADDRESS`: The address of the sender's Ethereum account, represented in hexadecimal format with the `0x` prefix. For example, `0x123abc...`.\n- `RECEIVER_ADDRESS`: The address of the receiver's Ethereum account, represented in hexadecimal format with the `0x` prefix. For example, `0x456def...`.\n- `PRIVATE_KEY`: The private key of an Ethereum account with sufficient funds to perform the transaction, represented in hexadecimal format with the `0x` prefix.\n- `NETWORK`: The network you want to connect to. There are two options: `era` which will connect to the L2 node and `eth` which will connect to the L1 node.\n\nThis command executes the `simple_payment` binary using the provided Makefile.\n\n### Conclusion\n\nCongratulations! You have successfully completed the \"Getting Started\" guide for the `zksync-web3-rs` SDK. You have learned how to send a simple payment transaction example using EIP1559 transactions on zkSync Era.\n\nBy exploring the example code and the repository's documentation, you can further enhance your understanding of interacting with zkSync Era's testnet using the `zksync-web3-rs` SDK.\n\nFeel free to experiment with different configurations and explore other functionalities provided by the SDK.\n\nIf you have any questions or need further assistance, don't hesitate to reach out to the repository's community or maintainers.\n\nHappy coding!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flambdaclass%2Fzksync-web3-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flambdaclass%2Fzksync-web3-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flambdaclass%2Fzksync-web3-rs/lists"}