From 03266513a53e8f0bacc296ba8d4157ac09b8e4cb Mon Sep 17 00:00:00 2001 From: Sabrina Ferguson Date: Fri, 12 Apr 2024 16:16:58 -0400 Subject: [PATCH] chore: edit quick-start contents --- bun.lockb | Bin 623656 -> 623656 bytes content/10.quick-start/00.index.md | 140 ++++++++++++++++ .../{1.index.md => 10.hello-zksync.md} | 20 +-- ...deploy_factory.md => 20.deploy-factory.md} | 10 +- .../{3.testing.md => 30.testing.md} | 12 +- .../{4.upgrading.md => 40.upgrading.md} | 14 +- .../{5.paymaster.md => 50.paymaster.md} | 21 +-- .../_foundry_deploy_contract_factory.md | 101 ++++------- .../_hardhat_deploy_contract_factory.md | 157 ++++++++---------- .../_foundry_deploy_contract.md | 29 +--- .../_hardhat_deploy_contract.md | 64 +++---- .../10.quick-start/_partials/_setup-wallet.md | 10 ++ .../_paymasters/_approval_paymaster_flow.md | 81 ++++----- .../_paymasters/_general_paymaster_flow.md | 79 ++++----- .../_testing/_foundry_contract_testing.md | 29 +--- .../_testing/_hardhat_contract_testing.md | 76 ++++----- .../_hardhat_beacon_contract_upgradability.md | 103 +++++------- .../_beacon_proxy_contract_upgradability.md | 6 +- ...dhat_transparent_contract_upgradability.md | 96 ++++------- ...ransparent_proxy_contract_upgradability.md | 4 +- .../_hardhat_uups_contract_upgradability.md | 87 ++++------ .../_uups_contract_upgradability.md | 4 +- content/_partials/_deploy-contract.md | 19 --- .../_environment-setup-with-foundry.md | 48 ++---- .../_environment-setup-with-zksync-cli.md | 39 ----- content/_partials/_setting-up-your-wallet.md | 40 ----- 26 files changed, 534 insertions(+), 755 deletions(-) create mode 100644 content/10.quick-start/00.index.md rename content/10.quick-start/{1.index.md => 10.hello-zksync.md} (72%) rename content/10.quick-start/{2.deploy_factory.md => 20.deploy-factory.md} (85%) rename content/10.quick-start/{3.testing.md => 30.testing.md} (83%) rename content/10.quick-start/{4.upgrading.md => 40.upgrading.md} (76%) rename content/10.quick-start/{5.paymaster.md => 50.paymaster.md} (76%) rename content/10.quick-start/{_index => _hello-zksync}/_foundry_deploy_contract.md (80%) rename content/10.quick-start/{_index => _hello-zksync}/_hardhat_deploy_contract.md (80%) create mode 100644 content/10.quick-start/_partials/_setup-wallet.md delete mode 100644 content/_partials/_deploy-contract.md delete mode 100644 content/_partials/_environment-setup-with-zksync-cli.md delete mode 100644 content/_partials/_setting-up-your-wallet.md diff --git a/bun.lockb b/bun.lockb index f73cd0ebab1e0f48329080fb671dff14e1676a39..883b07489c7869d369b1705610eab4e127c3fff4 100755 GIT binary patch delta 43 ycmZ3{p|+w!t)Ydng{g(Pg{6gc3)@dqcE&hEJtIAXHZ!(1Gxjz!j%{X~8h!vcf(*d` delta 43 vcmZ3{p|+w!t)Ydng{g(Pg{6gc3)@dqb|wZeXftDLGh=Tv + + +You will need to install a couple tools to effectively use `zksync-cli`: + +#### Install Node.js or Bun.sh + +You will need either Node.js or Bun.sh. +The choice depends on your project's requirements and personal preference for package management and execution speed. +If you are unfamiliar with both, choose Node.js. + +- Node.js + - Download the Long-Term Support (LTS) version from the :external-link{text="official Node.js website" href="https://nodejs.org/en/download"}. + - For first-time users, the :external-link{text="Node.js usage guide" href="https://nodejs.org/api/synopsis.html#usage"} + offers comprehensive instructions on getting started. +- Bun.sh + - Obtain the latest version from the :external-link{text="Bun installation page" href="https://bun.sh/docs/installation"}. + Bun.sh is known for its high performance and modern JavaScript features. + +### Setup era local node (optional) + +Our Quick Start series will have you compile and deploy contracts to +zkSync Sepolia testnet which requires you to have ETH in your wallet for funding transactions. +Our `zksync-cli` tool provides a way for you to setup a test node locally. +This era local node allows for quicker testing and debugging processes without incurring testnet transaction costs. + +#### Install Docker + +The era local node will need Docker to run locally on your machine. +Download the appropriate version from the :external-link{text="Docker website" href="https://docs.docker.com/engine/install/"}. + +#### Run a local zkSync Era node + +Run the following command in your terminal: + +```bash +zksync-cli dev start +``` + +Choose "In memory node" to deploy a local zkSync Era node in a Docker container. + +The local era node will also include pre-configured rich wallets for use, + + + +Your local zkSync Era node is accessible at **[http://127.0.0.1:8011](http://127.0.0.1:8011/)**, ready for deployment or testing purposes. + +## Choose Hardhat or Foundry + +Our Quickstart series provides two options for your learning process using +either Hardhat or Foundry. Pick one to use and stick with as you go through +each of the guides. + + + +### Install foundry-zksync + +If you choose to use Foundry for the Quick Start series, you will need to +install the `foundry-zksync` tool. This tool is a specialized fork of Foundry, tailored for zkSync. +It extends Foundry's capabilities for Ethereum app development to support zkSync, +allowing for the compilation, deployment, testing, and interaction with smart contracts on zkSync. + +::callout{icon="i-heroicons-information-circle-16-solid" color="amber"} +`foundry-zksync` is still in an alpha stage, so some features might not be fully supported +yet and may not work as fully intended. It is open-sourced and contributions are welcome. +:: + +Install `foundry-zksync` with the following command: + +```bash +curl -L https://foundry-zksync.zksync.io | bash +``` + +## Fund your wallet + +If you did not set up a local era node for development and plan to use zkSync Sepolia testnet, you will need testnet ETH to fund transactions. + +1. Obtaining Testnet ETH: + + - Use the [LearnWeb3 faucet](https://learnweb3.io/faucets/zksync_sepolia/) + to directly receive testnet ETH on zkSync Sepolia. + - Alternatively, acquire SepoliaETH from [recommended faucets](https://www.notion.so/tooling/network-faucets.md) and + transfer it to the zkSync Sepolia testnet via the [zkSync bridge](https://portal.zksync.io/bridge/?network=sepolia). + +1. Verify your balance: + + - Check your wallet's balance using the [zkSync Sepolia explorer](https://sepolia.explorer.zksync.io/). + +## Configure your wallet in a project + +To deploy contracts, you'll need to securely add your wallet's private key to the project environment. Follow these steps when you set up a new project: + +1. **Extract Your Private Key:** + + - If you are using the local era node, use a private key from the available rich accounts. Otherwise, find your personal wallet's private key. For MetaMask users, here's how to :external-link{ text="export your wallet's private key" href="https://support.metamask.io/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key" }. + +1. **Prepare the Environment File:** + - Locate the **`.env-example`** file in your project directory. + - Rename this file to **`.env`**. + +1. **Add Your Private Key:** + - Open the `.env` file and add your private key in the following format: + + ```sh + WALLET_PRIVATE_KEY=your_private_key_here + ``` + + - Replace **`your_private_key_here`** with your actual private key. + +## Next Steps + +You should now have a fully working local environment to build new projects on zkSync! + +- Continue to [Hello zkSync!](/quick-start/hello-zksync) to begin the series on building a crowdfunding campaign for Zeek. + +- You can skip on to creating your own projects using `zksync-cli` with your fully set up local dev environment. diff --git a/content/10.quick-start/1.index.md b/content/10.quick-start/10.hello-zksync.md similarity index 72% rename from content/10.quick-start/1.index.md rename to content/10.quick-start/10.hello-zksync.md index 8133d6cb..20f9e7a2 100644 --- a/content/10.quick-start/1.index.md +++ b/content/10.quick-start/10.hello-zksync.md @@ -3,29 +3,27 @@ title: Hello zkSync! description: Learn to deploy smart contracts efficiently in the zkSync environment. --- -Welcome to the Quickstart Guide for deploying smart contracts on zkSync! In this guide, we'll walk you through the process -of creating and deploying a simple smart contract that creates a crowdfunding campaign for Zeek. +Welcome to the Quickstart Guide for deploying smart contracts on zkSync! In this series, we'll walk you through the process +of creating and deploying a simple smart contract that creates a crowdfunding campaign for Zeek. In this section you will learn the following: -:check-icon Initializing a new project with zkSync-cli. +:check-icon Initialize a new project with zkSync-cli. -:check-icon Crafting a smart contract to fund Zeek's latest adventure. +:check-icon Craft a smart contract to fund Zeek's latest adventure. -:check-icon Deploying the contract on the zkSync Era using your choice of Hardhat or Foundry. +:check-icon Deploy the contract on the zkSync Era using your choice of Hardhat or Foundry. Let's dive in and start your developer journey on zkSync! -## Framework selection - Select the framework you want to get started using zkSync Era with. ::content-switcher --- items: [{ label: 'Hardhat', - partial: '_index/_hardhat_deploy_contract' + partial: '_hello-zksync/_hardhat_deploy_contract' }, { label: 'Foundry', - partial: '_index/_foundry_deploy_contract' + partial: '_hello-zksync/_foundry_deploy_contract' }] --- :: @@ -33,9 +31,9 @@ items: [{ ## Takeaways - **EVM Compatibility:** zkSync is EVM compatible and you can write smart contracts in Solidity or Vyper. -- **Development Tools:** zkSync supports your favorite development toolkit Hardhat and Foundry. - **Custom Compilation:** Contracts deployed to zkSync are compiled using `zksolc` or `zkvyper` as they generate a special bytecode for zkSync's ZKEVM. +- **Development Tools:** zkSync supports your favorite development toolkit Hardhat and Foundry. ## Next steps @@ -43,7 +41,7 @@ Having successfully deployed your first contract on zkSync, you're well on your a proficient zkSync developer. To expand your expertise: - **Explore Contract Factories:** Enhance your project by building a contract factory -for the `CrowdfundingCampaign` contract in the next guide. This will allow you to efficiently +for the `CrowdfundingCampaign` contract in the [next guide](/quick-start/deploy-factory). This will allow you to efficiently manage multiple crowdfunding campaigns, each with its own unique parameters. - **Dive Deeper into zkSync Features:** Investigate advanced zkSync features such as account abstraction, and paymasters. diff --git a/content/10.quick-start/2.deploy_factory.md b/content/10.quick-start/20.deploy-factory.md similarity index 85% rename from content/10.quick-start/2.deploy_factory.md rename to content/10.quick-start/20.deploy-factory.md index 975783bc..2931f958 100644 --- a/content/10.quick-start/2.deploy_factory.md +++ b/content/10.quick-start/20.deploy-factory.md @@ -1,21 +1,21 @@ --- title: Contract Factories -description: Learn how to deploy and manage crowdfunding smart contracts on zkSync using contract factories. +description: Learn how to deploy and manage multiple smart contracts on zkSync using contract factories. --- This second quickstart installment advances from your introductory exploration of smart contract deployment to dive into the utility of contract factories. Through this guide, you'll learn how to streamline the deployment of multiple crowdfunding campaigns using a single contract factory, leveraging the foundational `CrowdfundingCampaign` contract in the first guide. -:check-icon Advancing your zkSync development journey with contract factories. +:check-icon Advance your zkSync development journey with contract factories. -:check-icon Constructing a contract factory to create multiple crowdfunding campaigns. +:check-icon Construct a contract factory to create multiple crowdfunding campaigns. -:check-icon Seamlessly deploying your contract factory on zkSync Era, using either Hardhat or Foundry. +:check-icon Seamlessly deploy your contract factory on zkSync Era, using either Hardhat or Foundry. Let's explore the efficiency and scalability that contract factories bring. -### What is a contract factory? +## What is a contract factory? A contract factory is a design pattern that allows for the creation of multiple contract instances from a single "factory" contract. It's essentially a contract diff --git a/content/10.quick-start/3.testing.md b/content/10.quick-start/30.testing.md similarity index 83% rename from content/10.quick-start/3.testing.md rename to content/10.quick-start/30.testing.md index fda3f389..5d0eec48 100644 --- a/content/10.quick-start/3.testing.md +++ b/content/10.quick-start/30.testing.md @@ -9,17 +9,15 @@ of testing. This guide will walk you through the steps to ensure your `Crowdfund contracts, introduced in our first guide and efficiently deployed through contract factories in the second, work flawlessly. -:check-icon Elevating your zkSync toolkit with robust contract testing techniques. +:check-icon Elevate your zkSync toolkit with robust contract testing techniques. -:check-icon Crafting comprehensive tests for your `CrowdfundingCampaign` to ensure reliability and security. +:check-icon Craft comprehensive tests for your `CrowdfundingCampaign` to ensure reliability and security. -:check-icon Using Hardhat or Foundry to write and run tests, ensuring your campaigns are ready. +:check-icon Use Hardhat or Foundry to write and run tests, ensuring your campaigns are ready. Dive into the world of smart contract testing and solidify the foundation of your zkSync projects. -## Framework selection - -Select the framework you want to get started using zkSync Era with. +## Setup the project ::content-switcher --- @@ -49,7 +47,7 @@ that enhance the testing process. With a solid foundation in contract testing, you're well-equipped to advance your zkSync development journey. Consider the following steps to further your expertise: -- **Upgradeability**: Delve into the next guide focusing on contract upgradability. +- **Upgradeability**: Delve into the [next guide](/quick-start/upgrading) focusing on contract upgradability. Learning to make your contracts upgradeable will enable you to update and improve your smart contracts over time without losing state or funds. - **Advanced zkSync Integrations:** Explore deeper into zkSync's ecosystem by diff --git a/content/10.quick-start/4.upgrading.md b/content/10.quick-start/40.upgrading.md similarity index 76% rename from content/10.quick-start/4.upgrading.md rename to content/10.quick-start/40.upgrading.md index 90edbf30..53d5071e 100644 --- a/content/10.quick-start/4.upgrading.md +++ b/content/10.quick-start/40.upgrading.md @@ -3,22 +3,20 @@ title: Upgradability description: Learn to make smart contracts upgradeable within the zkSync ecosystem. --- -Welcome back to our Quickstart Series, the express lane to zkSync development! In this fourth installment, we embark on a journey through contract upgradability, an important aspect for maintaining and enhancing smart contracts over time. This guide will -lead you through the strategies and practices for making the `CrowdfundingCampaign` contract, -introduced in the first guide and brought to life in subsequent guides, **upgradeable**. +lead you through the strategies and practices for making the `CrowdfundingCampaign` contract, **upgradeable**. -:check-icon Harnessing advanced techniques for contract upgradability in zkSync. +:check-icon Harness advanced techniques for contract upgradability in zkSync. -:check-icon Implementing upgradeable patterns for the `CrowdfundingCampaign` to ensure long-term adaptability and improvement. +:check-icon Implement upgradeable patterns for the `CrowdfundingCampaign` to ensure long-term adaptability and improvement. -:check-icon Leveraging tools and best practices in zkSync to facilitate seamless contract upgrades. +:check-icon Leverage tools and best practices in zkSync to facilitate seamless contract upgrades. Begin to understand smart contract evolution and empower your zkSync applications with the flexibility of upgradability. -### Select preferred upgrade mechanism +Select your preferred upgrade mechanism: ::content-switcher --- @@ -50,7 +48,7 @@ functionalities evolve. This approach provides a resilient framework for your dA ### Next Steps -- **Exploring Paymasters:** Dive into the next guide focused on using paymasters +- **Exploring Paymasters:** Continue on to the next guide focused on [using paymasters](/quick-start/paymaster) with your smart contracts. Paymasters abstract gas payments in transactions, offering new models for transaction fee management and enhancing user experience in dApps. - **Advanced zkSync Integrations:** Explore deeper into zkSync's ecosystem by diff --git a/content/10.quick-start/5.paymaster.md b/content/10.quick-start/50.paymaster.md similarity index 76% rename from content/10.quick-start/5.paymaster.md rename to content/10.quick-start/50.paymaster.md index cb03018a..147ab275 100644 --- a/content/10.quick-start/5.paymaster.md +++ b/content/10.quick-start/50.paymaster.md @@ -1,31 +1,32 @@ --- title: Paymaster -description: Learn how to write and customize your documentation. +description: Implement a paymaster flow into your project. --- -WWelcome back to our Quickstart Series on mastering zkSync development! In this guide, we move beyond the basics +Welcome to the final part of our Quickstart Series on mastering zkSync development! +In this guide, we move beyond the basics of smart contract deployment and the creation of contract factories to explore the innovative concept of paymasters in the zkSync ecosystem. This guide will illuminate the power of paymasters to revolutionize transaction fee management and enhance user experiences within your dApps. -:check-icon Delving deeper into zkSync development with the introduction of paymasters. +:check-icon Delve deeper into zkSync development with the introduction of paymasters. -:check-icon Learning how paymasters can cover transaction fees for your dApp users, enhancing accessibility and user experience. +:check-icon Learn how paymasters can cover transaction fees for your dApp users, enhancing accessibility and user experience. -:check-icon Discovering the flexibility of fee payment with paymasters, including the ability to pay +:check-icon Discover the flexibility of fee payment with paymasters, including the ability to pay fees in ERC20 tokens on zkSync Era, using Hardhat or Foundry. Embark on this journey to understand how paymasters can add a new layer of functionality and user-friendliness to your decentralized applications. -### What are Paymasters? +## What are Paymasters? Paymasters in the zkSync ecosystem represent a groundbreaking approach to handling transaction fees. They are special accounts designed to subsidize transaction costs for other accounts, potentially making certain transactions free for end-users. This feature is particularly useful for dApp developers looking to improve their platform's accessibility and user experience by covering transaction fees on behalf of their users. -### Built-in Paymaster Flows +## Built-in Paymaster Flows Paymasters can operate under various flows, some of which may require user interaction, such as setting allowances for token swaps. These flows enable paymasters to support a wide range of use cases, from simple fee subsidies @@ -33,16 +34,16 @@ to more complex scenarios involving ERC20 token exchanges for transaction fees. - **General Paymaster Flow:** This default flow requires no preliminary actions from users, allowing paymasters to interpret transaction data as needed to cover fees. - + - **Approval-Based Paymaster Flow:** For operations requiring user permissions, such as token allowances, this flow provides a structured approach. It ensures that user tokens can be seamlessly exchanged for transaction fees, subject to user-approved limits. -As we delve into paymasters, remember that while they offer enhanced flexibility for fee management, their +As we explore paymasters, remember that while they offer enhanced flexibility for fee management, their implementation should always prioritize security and user trust. This guide aims to equip you with the knowledge to effectively incorporate paymasters into your zkSync projects, paving the way for more user-friendly and accessible dApps. -## Paymaster flow selection +## Paymaster flow Select the paymaster type you want to get started using zkSync Era with. diff --git a/content/10.quick-start/_deploy_factory/_foundry_deploy_contract_factory.md b/content/10.quick-start/_deploy_factory/_foundry_deploy_contract_factory.md index d6d72942..8a21c83b 100644 --- a/content/10.quick-start/_deploy_factory/_foundry_deploy_contract_factory.md +++ b/content/10.quick-start/_deploy_factory/_foundry_deploy_contract_factory.md @@ -2,34 +2,16 @@ title: Foundry | Deploy Contract Factory --- -`foundry-zksync` is a specialized fork of Foundry, tailored for zkSync. -It extends Foundry's capabilities for Ethereum app development to support zkSync, -allowing for the compilation, deployment, testing, and interaction with smart contracts on zkSync. - -::callout{icon="i-heroicons-information-circle-16-solid" color="amber"} -`foundry-zksync` is still in an alpha stage, so some features might not be fully supported -yet and may not work as fully intended. It is open-sourced and contributions are welcomed. -:: - - -## Step 1: Setting up environment :display-partial{path = "/_partials/_environment-setup-with-foundry"} -## Step 2: Set up wallet +## Set up your wallet -Deploying contracts on the zkSync Sepolia testnet requires having testnet ETH. -If you're working within the local development environment, -you can utilize pre-configured rich wallets and skip this step. -For testnet deployments, follow these steps to secure your funds: +:display-partial{path="quick-start/_partials/_setup-wallet"} -:display-partial{path = "/_partials/_setting-up-your-wallet"} - -## Step 3: Deploying contract with factory +## Review the CrowdfundingFactory contract With our environment and wallet configured, we're set to review the `CrowdfundingFactory.sol` -contract that is provided during the initialization step in the [`/src` directory](https://github.com/dutterbutter/zksync-foundry-quickstart-guide/blob/db/deploy-contract-factory/src/CrowdfundFactory.sol). +contract that is provided under the [`/src` directory](https://github.com/dutterbutter/zksync-foundry-quickstart-guide/blob/db/deploy-contract-factory/src/CrowdfundFactory.sol). The `CrowdfundingFactory.sol`contract will be used to deploy multiple instances of the `CrowdfundingCampaign.sol` contract from the previous guide. @@ -107,63 +89,46 @@ Compiling contracts for zkSync Era with zksolc v1.4.0 The compiled zkEVM artifacts will be located in the `/zkout` folder, and the solc artifacts will be located in the `/out` folder. -### Deploy +## Deploy a CrowdfundingCampaign with CrowdfundingFactory This section outlines the steps to deploy the `CrowdfundingCampaign` contract using our new `CrowdfundingFactory`. -Let's start by deploying the `CrowdfundingFactory` contract. Execute the following +1. Let's start by deploying the `CrowdfundingFactory` contract. Execute the following command: -```bash -forge create src/CrowdfundFactory.sol:CrowdfundingFactory --factory-deps src/CrowdfundingCampaign.sol:CrowdfundingCampaign --rpc-url zkSyncSepoliaTestnet --chain 300 --private-key --zksync -# To deploy the contract on local in-memory node: -# forge script script/DeployFactory.s.sol:DeployFactoryAndCreateCampaign --rpc-url inMemoryNode --broadcast --zksync -``` - -#### Expected output - -Upon a successfull deployment you'll receive details of the deploying address, the contract address, -and the transaction hash, like so: - -```bash -Deployer: 0x89E0Ff69Cc520b55C9F7Bcd3EAC17e81d9bB8dc2 -Deployed to: 0x607545Fd35ef49d7445555ddFa22938fD4Efb219 -Transaction hash: 0x94e7a97bb64c2bacffbd2a47f3c10021a80156d11082c079046a426c99518d28 -``` - -Using the `CrowdfundingFactory` contract address let's deploy our `CrowdfundingCampaign`: - -```bash -cast send 0x607545Fd35ef49d7445555ddFa22938fD4Efb219 "createCampaign(uint256)" "1" --rpc-url zkSyncSepoliaTestnet --chain 300 --private-key -# To use the contract factory on local in-memory node: -# cast send 0x607545Fd35ef49d7445555ddFa22938fD4Efb219 "createCampaign(uint256)" "1" --rpc-url inMemoryNode --chain 260 --private-key -``` - -#### Expected output + ```bash + forge create src/CrowdfundFactory.sol:CrowdfundingFactory --factory-deps src/CrowdfundingCampaign.sol:CrowdfundingCampaign --rpc-url zkSyncSepoliaTestnet --chain 300 --private-key --zksync + # To deploy the contract on local in-memory node: + # forge script script/DeployFactory.s.sol:DeployFactoryAndCreateCampaign --rpc-url inMemoryNode --broadcast --zksync + ``` -Upon a successfull deployment you'll receive details of the transaction, including the -contract address of our crowdfunding campaign: + Upon a successfull deployment you'll receive details of the deploying address, the contract address, + and the transaction hash, like so: -```bash -blockHash 0x7f8dfcd365b4ba5ac690e94aedb5fdb2bdb5ef12b2ff68672ab58c7a89738161 -blockNumber 1576375 -contractAddress 0x95f83473b88B5599cdB273F976fB3DC66DEA1c1D -... -... -``` - -**Key Components:** + ```bash + Deployer: 0x89E0Ff69Cc520b55C9F7Bcd3EAC17e81d9bB8dc2 + Deployed to: 0x607545Fd35ef49d7445555ddFa22938fD4Efb219 + Transaction hash: 0x94e7a97bb64c2bacffbd2a47f3c10021a80156d11082c079046a426c99518d28 + ``` -**Deployment Workflow:** +1. Using the `CrowdfundingFactory` contract address let's deploy our `CrowdfundingCampaign`: -- Initiates by deploying the `CrowdfundingFactory` through `forge create --zksync`. -- Using the factory's deployed address to form a `factoryContract` instance, -facilitating access to the factory's functionalities. + ```bash + cast send 0x607545Fd35ef49d7445555ddFa22938fD4Efb219 "createCampaign(uint256)" "1" --rpc-url zkSyncSepoliaTestnet --chain 300 --private-key + # To use the contract factory on local in-memory node: + # cast send 0x607545Fd35ef49d7445555ddFa22938fD4Efb219 "createCampaign(uint256)" "1" --rpc-url inMemoryNode --chain 260 --private-key + ``` -**Initiating Campaigns:** + Upon a successfull deployment you'll receive details of the transaction, including the + contract address of our crowdfunding campaign: -- Executes the `factoryContract`'s `createCampaign` function to create and deploy a new -crowdfunding campaign, with the specified funding target. + ```bash + blockHash 0x7f8dfcd365b4ba5ac690e94aedb5fdb2bdb5ef12b2ff68672ab58c7a89738161 + blockNumber 1576375 + contractAddress 0x95f83473b88B5599cdB273F976fB3DC66DEA1c1D + ... + ... + ``` 🌟 Brilliant! Your contract factory and its first crowdfunding campaign are now operational. diff --git a/content/10.quick-start/_deploy_factory/_hardhat_deploy_contract_factory.md b/content/10.quick-start/_deploy_factory/_hardhat_deploy_contract_factory.md index a5e7a8d9..54fdaac0 100644 --- a/content/10.quick-start/_deploy_factory/_hardhat_deploy_contract_factory.md +++ b/content/10.quick-start/_deploy_factory/_hardhat_deploy_contract_factory.md @@ -1,61 +1,42 @@ --- title: Hardhat | Deploy Contract Factory --- - -Hardhat is an Ethereum development environment, designed for easy smart contract -development in Solidity. zkSync provides its own plugins which makes working with -contracts on zkSync simple and efficient. - -## Step 1: Setting up environment -:display-partial{path = "/_partials/_environment-setup-with-zksync-cli"} -::drop-panel - ::panel{label="Initialize project"} - Run the following command in your terminal to initialize the project. - - ```sh - git clone https://github.com/dutterbutter/zksync-quickstart-guide.git - cd zksync-quickstart-guide - git checkout db/contract-factories - ``` - Install the dependencies: +Run the following command in your terminal to initialize the project. - ::code-group - - ```bash [yarn] - yarn install - ``` +```sh +git clone https://github.com/dutterbutter/zksync-quickstart-guide.git +cd zksync-quickstart-guide +git checkout db/contract-factories +``` - ```bash [pnpm] - pnpm run install - ``` +Install the dependencies: - ```bash [npm] - npm run install - ``` +::code-group - ```bash [bun] - bun run install - ``` +```bash [yarn] +yarn install +``` - :: - :: -:: +```bash [pnpm] +pnpm install +``` -## Step 2: Set up wallet +```bash [npm] +npm install +``` -Deploying contracts on the zkSync Sepolia testnet requires having testnet ETH. -If you're working within the local development environment, -you can utilize pre-configured rich wallets and skip this step. -For testnet deployments, follow these steps to secure your funds: +```bash [bun] +bun install +``` -:display-partial{path = "/_partials/_setting-up-your-wallet"} +:: -## Step 3: Deploying contract with factory +## Deploy contract with factory With our environment and wallet configured, we're set to review the `CrowdfundingFactory.sol` -contract that is provided during the initialization step in the [`/contracts` directory](https://github.com/dutterbutter/zksync-quickstart-guide/blob/db/contract-factories/contracts/CrowdfundFactory.sol). +contract that is provided under the [`/contracts` directory](https://github.com/dutterbutter/zksync-quickstart-guide/blob/db/contract-factories/contracts/CrowdfundFactory.sol). The `CrowdfundingFactory.sol`contract will be used to deploy multiple instances of the `CrowdfundingCampaign.sol` contract from the previous guide. @@ -91,7 +72,8 @@ the `CrowdfundingCampaign.sol` contract from the previous guide. :: The `CrowdfundingFactory` contract automates the creation and oversight of -`CrowdfundingCampaign` contracts, each with its distinct funding goals, it features: +`CrowdfundingCampaign` contracts, each with their own distinct funding goals. +The factory contract features: - **Campaign Creation**: Utilizes the `createCampaign` method to initiate a new `CrowdfundingCampaign` contract. This function takes a `fundingGoal` as an argument, @@ -108,8 +90,6 @@ making it efficient to launch and manage multiple campaigns. :display-partial{path = "/_partials/_compile-solidity-contracts"} -#### Expected Output - Upon successful compilation, you'll receive output detailing the `zksolc` and `solc` versions used during compiling and the number of Solidity files compiled. @@ -122,62 +102,59 @@ Successfully compiled 2 Solidity file The compiled artifacts will be located in the `/artifacts-zk` folder. -### Deploy +### Deploy via the CrowdfundingFactory This section outlines the steps to deploy the `CrowdfundingCampaign` contract using our new `CrowdfundingFactory`. The deployment script is located at `/deploy/deployUsingFactory.ts`. -```typescript -import { deployContract, getWallet } from "./utils"; -import { ethers } from "ethers"; -import { HardhatRuntimeEnvironment } from "hardhat/types"; - -export default async function (hre: HardhatRuntimeEnvironment) { - const contractArtifactName = "CrowdfundingFactory"; - const constructorArguments = []; - const crowdfundingFactory = await deployContract(contractArtifactName, constructorArguments); - - console.log(`🏭 CrowdfundingFactory address: ${crowdfundingFactory.target}`); - - const contractArtifact = await hre.artifacts.readArtifact("CrowdfundingFactory"); - const factoryContract = new ethers.Contract( - crowdfundingFactory.target, - contractArtifact.abi, - getWallet() - ); - - // Define funding goal for the campaign, e.g., 0.1 ether - const fundingGoalInWei = ethers.parseEther('0.1').toString(); - - // Use the factory to create a new CrowdfundingCampaign - const createTx = await factoryContract.createCampaign(fundingGoalInWei); - await createTx.wait(); - - // Retrieve the address of the newly created CrowdfundingCampaign - const campaigns = await factoryContract.getCampaigns(); - const newCampaignAddress = campaigns[campaigns.length - 1]; - - console.log(`πŸš€ New CrowdfundingCampaign deployed at: ${newCampaignAddress}`); - console.log('βœ… Deployment and campaign creation complete!'); -} -``` +::drop-panel + ::panel{label="deployUsingFactory.ts"} + + ```typescript + import { deployContract, getWallet } from "./utils"; + import { ethers } from "ethers"; + import { HardhatRuntimeEnvironment } from "hardhat/types"; + + export default async function (hre: HardhatRuntimeEnvironment) { + const contractArtifactName = "CrowdfundingFactory"; + const constructorArguments = []; + const crowdfundingFactory = await deployContract(contractArtifactName, constructorArguments); + + console.log(`🏭 CrowdfundingFactory address: ${crowdfundingFactory.target}`); -**Key Components:** + const contractArtifact = await hre.artifacts.readArtifact("CrowdfundingFactory"); + const factoryContract = new ethers.Contract( + crowdfundingFactory.target, + contractArtifact.abi, + getWallet() + ); -**Deployment Workflow:** + // Define funding goal for the campaign, e.g., 0.1 ether + const fundingGoalInWei = ethers.parseEther('0.1').toString(); -- Initiates by deploying the `CrowdfundingFactory` through `deployContract`. -- Using the factory's deployed address to form a `factoryContract` instance, -facilitating access to the factory's functionalities. + // Use the factory to create a new CrowdfundingCampaign + const createTx = await factoryContract.createCampaign(fundingGoalInWei); + await createTx.wait(); -**Initiating Campaigns:** + // Retrieve the address of the newly created CrowdfundingCampaign + const campaigns = await factoryContract.getCampaigns(); + const newCampaignAddress = campaigns[campaigns.length - 1]; -- Executes the `factoryContract`'s `createCampaign` function to create and deploy a new -crowdfunding campaign, with the specified funding target. + console.log(`πŸš€ New CrowdfundingCampaign deployed at: ${newCampaignAddress}`); + console.log('βœ… Deployment and campaign creation complete!'); + } + ``` -#### Deploy factory + :: +:: + +- The `deployUsingFactory.ts` script deploys the `CrowdfundingFactory` through the `deployContract` method. +- An instance of the factory is assigned to `factoryContract`. + This gives us access to the factory's functionalities. +- The `createCampaign` method is called on this instance to create + and deploy a new crowdfunding campaign contract. Execute the deployment command corresponding to your package manager. The default command deploys to the configured network in your Hardhat setup. For local deployment, append @@ -211,8 +188,6 @@ bun run hardhat deploy-zksync --script deployUsingFactory.ts :: -#### Expected Output - Upon successful deployment, you'll receive output detailing the deployment process, including the contract address, source, and encoded constructor arguments: diff --git a/content/10.quick-start/_index/_foundry_deploy_contract.md b/content/10.quick-start/_hello-zksync/_foundry_deploy_contract.md similarity index 80% rename from content/10.quick-start/_index/_foundry_deploy_contract.md rename to content/10.quick-start/_hello-zksync/_foundry_deploy_contract.md index 61de179e..eaa05010 100644 --- a/content/10.quick-start/_index/_foundry_deploy_contract.md +++ b/content/10.quick-start/_hello-zksync/_foundry_deploy_contract.md @@ -2,31 +2,13 @@ title: Foundry | Deploy Contract --- -`foundry-zksync` is a specialized fork of Foundry, tailored for zkSync. -It extends Foundry's capabilities for Ethereum app development to support zkSync, -allowing for the compilation, deployment, testing, and interaction with smart contracts on zkSync. - -::callout{icon="i-heroicons-information-circle-16-solid" color="amber"} -`foundry-zksync` is still in an alpha stage, so some features might not be fully supported -yet and may not work as fully intended. It is open-sourced and contributions are welcomed. -:: - - -## Step 1: Setting up environment :display-partial{path = "/_partials/_environment-setup-with-foundry"} -## Step 2: Set up wallet +## Set up your wallet -Deploying contracts on the zkSync Sepolia testnet requires having testnet ETH. -If you're working within the local development environment, -you can utilize pre-configured rich wallets and skip this step. -For testnet deployments, follow these steps to secure your funds: +:display-partial{path = "/quick-start/_partials/_setup-wallet"} -:display-partial{path = "/_partials/_setting-up-your-wallet"} - -## Step 3: Deploying your first contract +## Deploy your first contract With our environment and wallet configured, we're set to deploy our first contract. This guide introduces a crowdfunding campaign contract aimed at supporting Zeek's inventive ventures. @@ -97,7 +79,6 @@ Owned and deployed with a set funding goal, it features: ### Compile contract - Smart contracts deployed to zkSync must be compiled using our custom compiler. For this particular guide we are making use of `zksolc`. @@ -107,8 +88,6 @@ To compile the contracts in the project, run the following command: forge build --zksync ``` -#### Expected Output - Upon successful compilation, you'll receive output detailing the `zksolc` and `solc` versions used during compiling and the number of Solidity files compiled. @@ -166,8 +145,6 @@ forge script script/Deploy.s.sol:DeployCrowdfundContract --rpc-url zkSyncSepolia # forge script script/Deploy.s.sol:DeployCrowdfundContract --rpc-url inMemoryNode --broadcast --zksync ``` -#### Expected Output - Upon successful deployment, you'll receive output detailing the deployment process, including the contract address, transaction hash, and block number deployed to: diff --git a/content/10.quick-start/_index/_hardhat_deploy_contract.md b/content/10.quick-start/_hello-zksync/_hardhat_deploy_contract.md similarity index 80% rename from content/10.quick-start/_index/_hardhat_deploy_contract.md rename to content/10.quick-start/_hello-zksync/_hardhat_deploy_contract.md index 9dee1c9f..5d4b5d0d 100644 --- a/content/10.quick-start/_index/_hardhat_deploy_contract.md +++ b/content/10.quick-start/_hello-zksync/_hardhat_deploy_contract.md @@ -2,58 +2,46 @@ title: Hardhat | Deploy Contract --- -Hardhat is an Ethereum development environment, designed for easy smart contract development in Solidity. -zkSync provides its own plugins which makes working with contracts on zkSync simple and efficient. +Run the following command in your terminal to initialize the project. -## Step 1: Setting up environment -:display-partial{path = "/_partials/_environment-setup-with-zksync-cli"} -::drop-panel - ::panel{label="Initialize project"} - Run the following command in your terminal to initialize the project. - ```sh - git clone https://github.com/dutterbutter/zksync-quickstart-guide.git - cd zksync-quickstart-guide - ``` - Install the dependencies: +```sh +git clone https://github.com/dutterbutter/zksync-quickstart-guide.git +cd zksync-quickstart-guide +``` - ::code-group +Install the dependencies: - ```bash [yarn] - yarn install - ``` +::code-group - ```bash [pnpm] - pnpm run install - ``` +```bash [yarn] +yarn install +``` - ```bash [npm] - npm run install - ``` +```bash [pnpm] +pnpm install +``` - ```bash [bun] - bun run install - ``` +```bash [npm] +npm install +``` - :: - :: -:: +```bash [bun] +bun install +``` -## Step 2: Set up wallet +:: -Deploying contracts on the zkSync Sepolia testnet requires having testnet ETH. -If you're working within the local development environment, -you can utilize pre-configured rich wallets and skip this step. -For testnet deployments, follow these steps to secure your funds: +## Set up your wallet -:display-partial{path = "/_partials/_setting-up-your-wallet"} +:display-partial{path="quick-start/_partials/_setup-wallet"} -## Step 3: Deploying your first contract +## Deploy the CrowdfundingCampaign.sol contract -With our environment and wallet configured, we're set to deploy our first contract. This guide -introduces a crowdfunding campaign contract aimed at supporting Zeek's inventive ventures. +With our environment and wallet configured, we're set to deploy our first contract. +This guide introduces a crowdfunding campaign contract aimed at supporting Zeek's inventive ventures. Let's start by reviewing the starter contract in the [`contracts/` directory](https://github.com/dutterbutter/zksync-quickstart-guide/blob/main/contracts/Crowdfund.sol). ::drop-panel @@ -112,7 +100,7 @@ Let's start by reviewing the starter contract in the [`contracts/` directory](ht :: The `CrowdfundingCampaign` contract is designed for project crowdfunding. -Deployed with a set funding goal, it features: +This contract features: - A constructor to initialize the campaign's funding target. - The `contribute` method to log funds, triggering `ContributionReceived` and `GoalReached` events. diff --git a/content/10.quick-start/_partials/_setup-wallet.md b/content/10.quick-start/_partials/_setup-wallet.md new file mode 100644 index 00000000..e740dab6 --- /dev/null +++ b/content/10.quick-start/_partials/_setup-wallet.md @@ -0,0 +1,10 @@ +--- +title: Set up your wallet +--- + +Deploying contracts on the zkSync Sepolia testnet requires having testnet ETH. +If you're working within the local development environment, +you can utilize pre-configured rich wallets and skip this step. +For testnet deployments, you should have your wallet funded from the [previous step](/quick-start#fund-your-wallet). + +Ensure your project is configured to [use your wallet via the `.env` file](/quick-start#fund-your-wallet). diff --git a/content/10.quick-start/_paymasters/_approval_paymaster_flow.md b/content/10.quick-start/_paymasters/_approval_paymaster_flow.md index 1e11c44f..7239e96c 100644 --- a/content/10.quick-start/_paymasters/_approval_paymaster_flow.md +++ b/content/10.quick-start/_paymasters/_approval_paymaster_flow.md @@ -3,52 +3,44 @@ title: Approval Paymaster description: Learn to deploy contract factories in the zkSync environment. --- -## Step 1: Setting up environment -:display-partial{path = "/_partials/_environment-setup-with-zksync-cli"} -::drop-panel - ::panel{label="Initialize project"} - Run the following command in your terminal to initialize the project. +Run the following command in your terminal to initialize the project. - ```sh - git clone https://github.com/dutterbutter/zksync-quickstart-guide.git - cd zksync-quickstart-guide - git checkout db/contract-paymaster - ``` - Install the dependencies: +```sh +git clone https://github.com/dutterbutter/zksync-quickstart-guide.git +cd zksync-quickstart-guide +git checkout db/contract-paymaster +``` - ::code-group +Install the dependencies: - yarn install - ``` +::code-group - ```bash [pnpm] - pnpm run install - ``` +```bash [yarn] +yarn install - ```bash [npm] - npm run install - ``` +``` - ```bash [bun] - bun run install - ``` +```bash [pnpm] +pnpm install +``` - :: - :: -:: +```bash [npm] +npm install +``` + +```bash [bun] +bun install +``` -## Step 2: Set up wallet +:: -Deploying contracts on the zkSync Sepolia testnet requires having testnet ETH. -If you're working within the local development environment, -you can utilize pre-configured rich wallets and skip this step. -For testnet deployments, follow these steps to secure your funds: +## Set up your wallet -:display-partial{path = "/_partials/_environment-setup-with-zksync-cli"} +:display-partial{path = "/quick-start/_partials/_setup-wallet"} -## Step 3: Understanding ApprovalPaymaster contract +## Understanding the ApprovalPaymaster contract Let's start by reviewing the `ApprovalPaymaster.sol` contract in the `contracts/` directory: @@ -146,14 +138,10 @@ due to out-of-gas errors. It receives several parameters, including the transact - **`onlyBootloader`** Modifier: Ensures that certain methods are exclusively callable by the system's bootloader, adding an extra layer of security and control. -## Step 4: Deploying ApprovalPaymaster contract - -### Compile contract +## Deploy ApprovalPaymaster contract :display-partial{path = "/_partials/_compile-solidity-contracts"} -#### Expected Output - Upon successful compilation, you'll receive output detailing the `zksolc` and `solc` versions used during compiling and the number of Solidity files compiled. @@ -168,7 +156,7 @@ The compiled artifacts will be located in the `/artifacts-zk` folder. ### Deploy -This section outlines the steps to deploy the `GaslessPaymaster` contract. Recall our initial deployment `CrowdfundingCampaign` contract. +This section outlines the steps to deploy the `GaslessPaymaster` contract. Recall our initial deployment of the `CrowdfundingCampaign` contract. Deploying the `GaslessPaymaster` contract is the same. The deployment script is located at `/deploy/deploy.ts`. @@ -212,7 +200,6 @@ mirroring the deployment process used for the `CrowdfundingCampaign` contract. to cover transaction fees for users. The script sends a transaction from the deployer's wallet to the paymaster contract, ensuring it has sufficient balance to operate. -#### Deploy contract Execute the deployment command corresponding to your package manager. The default command deploys to the configured network in your Hardhat setup. For local deployment, append `--network inMemoryNode` to deploy to the local in-memory node running. @@ -245,8 +232,6 @@ bun run hardhat deploy-zksync --script deployGaslessPaymaster.ts :: -#### Expected Output - Upon successful deployment, you'll receive output detailing the deployment process, including the contract address, source, and encoded constructor arguments: @@ -265,13 +250,15 @@ Contract successfully verified on zkSync block explorer! Paymaster ETH balance is now 5000000000000000 ``` -## Step 5: Interacting with ApprovalPaymaster contract +## Interact with the ApprovalPaymaster contract -This section guides we'll navigate through the steps to interact with the `GeneralPaymaster` contract, +This section guides we'll navigate through the steps to interact with the `GaslessPaymaster` contract, using it to cover transaction fees for our operation. The interaction script is situated in the `/deploy/interact/` directory, named `interactWithPaymaster.ts`. +Ensure the `CONTRACT_ADDRESS` and `PAYMASTER_ADDRESS` variables are set to your deployed contract and paymaster addresses, respectively. + ```typescript import * as hre from "hardhat"; import { getWallet, getProvider } from "../utils"; @@ -332,7 +319,7 @@ export default async function() { console.log(`Transaction hash: ${transaction.hash}`); await transaction.wait(); - + let balanceAfterTransaction = await provider.getBalance(getWallet().address); // Check the wallet balance after the transaction // We only pay the contribution amount, so the balance should be less than before @@ -341,8 +328,6 @@ export default async function() { } ``` -Ensure the `CONTRACT_ADDRESS` and `PAYMASTER_ADDRESS` variables are set to your deployed contract and paymaster addresses, respectively. - **Key Components:** - **Paymaster Parameters:** Before executing transactions that involve the contract, the script prepares paymaster parameters using @@ -377,8 +362,6 @@ bun run hardhat deploy-zksync --script interact/interactWithPaymaster.ts :: -#### Expected Output - Upon successful usage, you'll receive output detailing the transaction: ```bash diff --git a/content/10.quick-start/_paymasters/_general_paymaster_flow.md b/content/10.quick-start/_paymasters/_general_paymaster_flow.md index 05549d07..682c9dda 100644 --- a/content/10.quick-start/_paymasters/_general_paymaster_flow.md +++ b/content/10.quick-start/_paymasters/_general_paymaster_flow.md @@ -3,53 +3,43 @@ title: General Paymaster description: Learn to deploy contract factories in the zkSync environment. --- -## Step 1: Setting up environment -:display-partial{path = "/_partials/_environment-setup-with-zksync-cli"} -::drop-panel - ::panel{label="Initialize project"} - Run the following command in your terminal to initialize the project. +Run the following command in your terminal to initialize the project. - ```sh - git clone https://github.com/dutterbutter/zksync-quickstart-guide.git - cd zksync-quickstart-guide - git checkout db/contract-paymaster - ``` - Install the dependencies: +```sh +git clone https://github.com/dutterbutter/zksync-quickstart-guide.git +cd zksync-quickstart-guide +git checkout db/contract-paymaster +``` - ::code-group +Install the dependencies: - ```bash [yarn] - yarn install - ``` +::code-group - ```bash [pnpm] - pnpm run install - ``` +```bash [yarn] +yarn install +``` - ```bash [npm] - npm run install - ``` +```bash [pnpm] +pnpm install +``` - ```bash [bun] - bun run install - ``` +```bash [npm] +npm install +``` - :: - :: -:: +```bash [bun] +bun install +``` -## Step 2: Set up wallet +:: -Deploying contracts on the zkSync Sepolia testnet requires having testnet ETH. -If you're working within the local development environment, -you can utilize pre-configured rich wallets and skip this step. -For testnet deployments, follow these steps to secure your funds: +## Set up your wallet -:display-partial{path = "/_partials/_environment-setup-with-zksync-cli"} +:display-partial{path = "/quick-start/_partials/_setup-wallet"} -## Step 3: Understanding GeneralPaymaster contract +## Understanding GeneralPaymaster contract Let's start by reviewing the `GeneralPaymaster.sol` contract in the `contracts/` directory: @@ -151,14 +141,10 @@ due to out-of-gas errors. It receives several parameters, including the transact - **`onlyBootloader`** Modifier: Ensures that certain methods are exclusively callable by the system's bootloader, adding an extra layer of security and control. -## Step 4: Deploying GeneralPaymaster contract - -### Compile contract +## Deploy the GeneralPaymaster contract :display-partial{path = "/_partials/_compile-solidity-contracts"} -#### Expected Output - Upon successful compilation, you'll receive output detailing the `zksolc` and `solc` versions used during compiling and the number of Solidity files compiled. @@ -217,7 +203,6 @@ mirroring the deployment process used for the `CrowdfundingCampaign` contract. to cover transaction fees for users. The script sends a transaction from the deployer's wallet to the paymaster contract, ensuring it has sufficient balance to operate. -#### Deploy contract Execute the deployment command corresponding to your package manager. The default command deploys to the configured network in your Hardhat setup. For local deployment, append `--network inMemoryNode` to deploy to the local in-memory node running. @@ -250,8 +235,6 @@ bun run hardhat deploy-zksync --script deployGaslessPaymaster.ts :: -#### Expected Output - Upon successful deployment, you'll receive output detailing the deployment process, including the contract address, source, and encoded constructor arguments: @@ -270,13 +253,15 @@ Contract successfully verified on zkSync block explorer! Paymaster ETH balance is now 5000000000000000 ``` -## Step 5: Interacting with GeneralPaymaster contract +## Interact with the GeneralPaymaster contract This section guides we'll navigate through the steps to interact with the `GeneralPaymaster` contract, using it to cover transaction fees for our operation. The interaction script is situated in the `/deploy/interact/` directory, named `interactWithPaymaster.ts`. +Ensure the `CONTRACT_ADDRESS` and `PAYMASTER_ADDRESS` variables are set to your deployed contract and paymaster addresses, respectively. + ::drop-panel ::panel{label="interactWithPaymaster.ts"} @@ -340,7 +325,7 @@ The interaction script is situated in the `/deploy/interact/` directory, named ` console.log(`Transaction hash: ${transaction.hash}`); await transaction.wait(); - + let balanceAfterTransaction = await provider.getBalance(getWallet().address); // Check the wallet balance after the transaction // We only pay the contribution amount, so the balance should be less than before @@ -352,8 +337,6 @@ The interaction script is situated in the `/deploy/interact/` directory, named ` :: :: -Ensure the `CONTRACT_ADDRESS` and `PAYMASTER_ADDRESS` variables are set to your deployed contract and paymaster addresses, respectively. - **Key Components:** - **Paymaster Parameters:** Before executing transactions that involve the contract, the script prepares paymaster parameters using @@ -364,8 +347,6 @@ used and the type of paymaster flow, which in this case is `General`. in transactions. This allows the paymaster to cover transaction fees, providing a seamless experience for users. -#### Use GaslessPaymaster - Execute the command corresponding to your package manager: ::code-group @@ -388,8 +369,6 @@ bun run hardhat deploy-zksync --script interact/interactWithPaymaster.ts :: -#### Expected Output - Upon successful usage, you'll receive output detailing the transaction: ```bash diff --git a/content/10.quick-start/_testing/_foundry_contract_testing.md b/content/10.quick-start/_testing/_foundry_contract_testing.md index 316e84b0..bfc523a3 100644 --- a/content/10.quick-start/_testing/_foundry_contract_testing.md +++ b/content/10.quick-start/_testing/_foundry_contract_testing.md @@ -2,19 +2,9 @@ title: Hardhat | Contract Testing --- -`foundry-zksync` is a specialized fork of Foundry, tailored for zkSync. -It extends Foundry's capabilities for Ethereum app development to support zkSync, -allowing for the compilation, deployment, testing, and interaction with smart contracts on zkSync. - -::callout{icon="i-heroicons-information-circle-16-solid" color="amber"} -`foundry-zksync` is still in an alpha stage, so some features might not be fully supported -yet and may not work as fully intended. It is open-sourced and contributions are welcomed. -:: - -## Step 1: Environment Configuration :display-partial{path = "/_partials/_environment-setup-with-foundry"} -## Step 2: Testing `CrowdfundingCampaign` contract +## Test the `CrowdfundingCampaign` contract Now that our setup is complete, it's time to focus on the core of this guide - testing our `CrowdfundingCampaign.sol` contract. Here's a quick @@ -86,7 +76,6 @@ reliability of the contract. ### Compile contract - Smart contracts deployed to zkSync must be compiled using our custom compiler. For this particular guide we are making use of `zksolc`. @@ -96,8 +85,6 @@ To compile the contracts in the project, run the following command: forge build --zksync ``` -#### Expected Output - Upon successful compilation, you'll receive output detailing the `zksolc` and `solc` versions used during compiling and the number of Solidity files compiled. @@ -113,7 +100,7 @@ Compiling contracts for zkSync Era with zksolc v1.4.0 The compiled zkEVM artifacts will be located in the `/zkout` folder, and the solc artifacts will be located in the `/out` folder. -### Testing +### Run the test command This section describes the testing `CrowdfundingCampaign.sol` contract. Let's start by reviewing the tests for `CrowdfundingCampaign.sol` contract provided @@ -137,7 +124,7 @@ contract CrowdfundingCampaignTest is Test { function setUp() public { owner = address(this); - + addr1 = vm.addr(1); addr2 = vm.addr(2); @@ -164,18 +151,16 @@ contract CrowdfundingCampaignTest is Test { assertEq(campaign.getTotalFundsRaised(), initialTotal + 0.8 ether); } - function test_EmitGoalReachedWhenFundingGoalMet() public { + function test_EmitGoalReachedWhenFundingGoalMet() public { vm.prank(addr1); vm.deal(addr1, 2 ether); vm.expectEmit(true, true, false, true); emit GoalReached(1 ether); - campaign.contribute{value: 1 ether}(); + campaign.contribute{value: 1 ether}(); } } ``` -**Testing Workflow:** - - **Environment Setup**: Leverages Foundry's `Test` contract and setup functions to prepare the test environment, ensuring a fresh state for each test case. - **Deployment and Address Simulation**: Deploys the `CrowdfundingCampaign` contract @@ -192,7 +177,7 @@ contributions from various addresses, ensuring accurate tracking of the total fu anticipate the `GoalReached` event when the funding goal is met, validating the contract's event logic and state transitions. -#### Execute tests +#### Run the tests Execute the test command: @@ -200,8 +185,6 @@ Execute the test command: forge test --zksync ``` -#### Expected Output - Upon completion, the test suite will provide a summary of all executed tests, indicating their success or failure: diff --git a/content/10.quick-start/_testing/_hardhat_contract_testing.md b/content/10.quick-start/_testing/_hardhat_contract_testing.md index 9baa0b31..5eeec7b9 100644 --- a/content/10.quick-start/_testing/_hardhat_contract_testing.md +++ b/content/10.quick-start/_testing/_hardhat_contract_testing.md @@ -1,50 +1,46 @@ --- title: Hardhat | Contract Testing --- - -Hardhat is an Ethereum development environment, designed for easy smart contract development in Solidity. -zkSync provides its own plugins which makes working with contracts on zkSync simple and efficient. - -## Step 1: Environment Configuration -::drop-panel - ::panel{label="Initialize project"} - Run the following command in your terminal to initialize the project. +Run the following command in your terminal to initialize the project. - ```sh - git clone https://github.com/dutterbutter/zksync-quickstart-guide.git - cd zksync-quickstart-guide - git checkout db/contract-testing - ``` - Install the dependencies: + ```sh + git clone https://github.com/dutterbutter/zksync-quickstart-guide.git + cd zksync-quickstart-guide + git checkout db/contract-testing + ``` - ::code-group + Install the dependencies: - ```bash [yarn] - yarn install - ``` + ::code-group - ```bash [pnpm] - pnpm run install - ``` + ```bash [yarn] + yarn install + ``` - ```bash [npm] - npm run install - ``` + ```bash [pnpm] + pnpm install + ``` - ```bash [bun] - bun run install - ``` + ```bash [npm] + npm install + ``` + + ```bash [bun] + bun install + ``` - :: :: -:: + +### Local Era Node While setting up a local development environment was previously optional, testing contracts requires a more structured setup. We'll use `hardhat-zksync` to run tests against an In-memory node, which operates seamlessly within a separate process for an optimized testing workflow. +If you have not set up your local era node yet, follow the instructions in the [Getting Started](/quick-start#setup-era-local-node-optional) section. + Within the `hardhat.config.ts`, you'll observe the `zksync` flag set to `true` under the `hardhat` network, indicating the integration with zkSync's testing environment. @@ -68,11 +64,9 @@ toolkit available for your project. import "@nomicfoundation/hardhat-chai-matchers"; ``` -Certainly! Here is the information about the test wallet configuration in a list format rather than a table: - -## Step 2: Test Wallet Configuration +## Test Wallet Configuration -For testing purposes, we use pre-configured, well-funded wallets. During this testing guide, we will leverage the following pre-configured wallet, +For testing purposes, we use pre-configured, well-funded wallets. During this testing guide, we will use the following pre-configured wallet, which eliminates the need for manual funding or setup: - **Account Address:** `0x36615Cf349d7F6344891B1e7CA7C72883F5dc049` @@ -80,7 +74,7 @@ which eliminates the need for manual funding or setup: This streamlined approach allows us to focus on writing and running effective tests. -## Step 3: Testing `CrowdfundingCampaign` contract +## Test `CrowdfundingCampaign` contract Now that our setup is complete, it's time to focus on the core of this guide - testing our `CrowdfundingCampaign.sol` contract. Here's a quick @@ -146,7 +140,7 @@ including potential failure scenarios. In this guide, we'll focus in on the `con method to ensure it's tested. As a challenge to hone your testing skills further, -consider devising additional tests for the `withdrawFunds`, `getTotalFundsRaised`, +consider writing additional tests for the `withdrawFunds`, `getTotalFundsRaised`, and `getFundingGoal` methods, expanding your test coverage and reinforcing the reliability of the contract. @@ -154,8 +148,6 @@ reliability of the contract. :display-partial{path = "/_partials/_compile-solidity-contracts"} -#### Expected Output - Upon successful compilation, you'll receive output detailing the `zksolc` and `solc` versions used during compiling and the number of Solidity files compiled. @@ -170,7 +162,7 @@ The compiled artifacts will be located in the `/artifacts-zk` folder. ### Testing -This section describes testing `CrowdfundingCampaign.sol` contract. Let's +This section describes testing the `CrowdfundingCampaign.sol` contract. Let's start by reviewing the tests for `CrowdfundingCampaign.sol` contract provided during the initialization step in the `/tests` directory, specifically the [`crowdFunding.test.ts` file](https://github.com/dutterbutter/zksync-quickstart-guide/blob/db/contract-testing/test/crowdFunding.test.ts). @@ -212,10 +204,6 @@ describe("CrowdfundingCampaign", function () { }); ``` -**Key Components:** - -**Testing Workflow:** - - **Initialization**: Each test case initializes with fresh contract instances and predefined rich wallet accounts to simulate various contributors and the contract owner. - **Deployment**: The `CrowdfundingCampaign` contract is deployed using the `deployContract` @@ -230,7 +218,7 @@ multiple addresses and update the `totalFundsRaised` accordingly. - **Goal Achievement**: Checks for the `GoalReached` event emission upon meeting the funding goal, confirming the contract's responsiveness to achieving its set target. -#### Execute tests +#### Run the tests Execute the test command corresponding to your package manager: ::code-group @@ -253,8 +241,6 @@ bun run hardhat test --network hardhat :: -#### Expected Output - Upon completion, the test suite will provide a summary of all executed tests, indicating their success or failure: diff --git a/content/10.quick-start/_upgrading/_beacon/_hardhat_beacon_contract_upgradability.md b/content/10.quick-start/_upgrading/_beacon/_hardhat_beacon_contract_upgradability.md index 744937b9..991b64e3 100644 --- a/content/10.quick-start/_upgrading/_beacon/_hardhat_beacon_contract_upgradability.md +++ b/content/10.quick-start/_upgrading/_beacon/_hardhat_beacon_contract_upgradability.md @@ -2,56 +2,43 @@ title: Hardhat | Contract Upgrading --- -Hardhat is an Ethereum development environment, designed for easy smart contract development in Solidity. -zkSync provides its own plugins which makes working with contracts on zkSync simple and efficient. - -## Step 1: Setting up environment -:display-partial{path = "/_partials/_environment-setup-with-zksync-cli"} -::drop-panel - ::panel{label="Initialize project"} - Run the following command in your terminal to initialize the project. +Run the following command in your terminal to initialize the project. - ```sh - git clone https://github.com/dutterbutter/zksync-quickstart-guide.git - cd zksync-quickstart-guide - git checkout db/contract-upgrade - ``` - Install the dependencies: +```sh +git clone https://github.com/dutterbutter/zksync-quickstart-guide.git +cd zksync-quickstart-guide +git checkout db/contract-upgrade +``` - ::code-group +Install the dependencies: - ```bash [yarn] - yarn install - ``` +::code-group - ```bash [pnpm] - pnpm run install - ``` +```bash [yarn] +yarn install +``` + +```bash [pnpm] +pnpm install +``` - ```bash [npm] - npm run install - ``` +```bash [npm] +npm install +``` - ```bash [bun] - bun run install - ``` +```bash [bun] +bun install +``` - :: - :: :: -## Step 2: Set up wallet - -Deploying contracts on the zkSync Sepolia testnet requires having testnet ETH. -If you're working within the local development environment, -you can utilize pre-configured rich wallets and skip this step. -For testnet deployments, follow these steps to secure your funds: +## Set up your wallet -:display-partial{path = "/_partials/_setting-up-your-wallet"} +:display-partial{path = "/quick-start/_partials/_setup-wallet"} -## Step 3: Adapting `CrowdfundingCampaign.sol` contract for upgradability +## Adapt `CrowdfundingCampaign.sol` contract for upgradability To adapt our `CrowdfundingCampaign.sol` contract for upgradability, we are transitioning to a proxy pattern. This approach separates the @@ -115,7 +102,7 @@ allowing for future upgrades without losing the contract's state. This restructuring prepares the `CrowdfundingCampaign` contract for upgradeability. -## Step 4: Deploy the `CrowdfundingCampaign` contract +## Deploy the `CrowdfundingCampaign` contract Now that the `CrowdfundingCampaign` contract is adapted for contract upgradability, let's proceed to deploy the contract so we may upgrade it in later steps. Since we've made changes to our contract we will @@ -143,8 +130,6 @@ bun run compile :: -#### Expected Output - Upon successful compilation, you'll receive output detailing the `zksolc` and `solc` versions used during compiling and the number of Solidity files compiled. @@ -159,8 +144,6 @@ The compiled artifacts will be located in the `/artifacts-zk` folder. ### Deploy -This guide details the process for deploying the upgraded `CrowdfundingCampaign` -contract, now enhanced with upgradability features. You'll find the necessary deployment script at [`/deploy/deployBeaconProxy.ts`](https://github.com/dutterbutter/zksync-quickstart-guide/blob/db/contract-upgrade/deploy/deployBeaconProxy.ts). ```typescript @@ -182,9 +165,9 @@ export default async function (hre: HardhatRuntimeEnvironment) { ); await beacon.waitForDeployment(); - const crowdfunding = await hre.zkUpgrades.deployBeaconProxy(deployer.zkWallet, + const crowdfunding = await hre.zkUpgrades.deployBeaconProxy(deployer.zkWallet, await beacon.getAddress(), contractArtifact, [fundingGoalInWei]); - + await crowdfunding.waitForDeployment(); } ``` @@ -202,7 +185,6 @@ allowing for seamless upgrades without altering the proxy's address. The `fundingGoalInWei parameter`, converted from ether to wei, is passed during this step to initialize the contract with a funding goal. -#### Deploy contract Execute the deployment command corresponding to your package manager. The default command deploys to the configured network in your Hardhat setup. For local deployment, append `--network inMemoryNode` to deploy to the local in-memory node running. @@ -235,8 +217,6 @@ bun run hardhat deploy-zksync --script deployBeaconProxy.ts :: -#### Expected Output - Upon successful deployment, you'll receive output detailing the deployment process, including the contract addresses of the implementation contract, the admin contract, and the beacon @@ -248,12 +228,14 @@ Beacon deployed at: 0x26410Bebf5Df7398DCBC5f00e9EBBa0Ddf471C72 Beacon proxy deployed at: 0xD58FA9Fb362Abf69cFc68A3545fD227165DAc167 ``` -## Step 5: Upgrading the `CrowdfundingCampaign` Contract +## Upgrade the `CrowdfundingCampaign` Contract With our initial setup deployed, we're ready to upgrade our `CrowdfundingCampaign.sol` contract by incorporating a deadline for contributions. This addition not only brings a new layer of functionality but also introduces the concept of time-based conditions through a `modifier`. + **Current Contract Overview:** @@ -300,12 +282,8 @@ function extendDeadline(uint256 _newDuration) public { This upgrade not only introduces the element of time to the campaign but also exemplifies the use of `modifiers` for enforcing contract conditions. -### Compile contract - :display-partial{path = "/_partials/_compile-solidity-contracts"} -#### Expected Output - Upon successful compilation, you'll receive output detailing the `zksolc` and `solc` versions used during compiling and the number of Solidity files compiled. @@ -320,10 +298,14 @@ The compiled artifacts will be located in the `/artifacts-zk` folder. ### Upgrading to `CrowdfundingCampaignV2` -This section describes the initiating the upgrade to `CrowdfundingCampaignV2.sol` contract. Let's +This section describes the upgrade process to `CrowdfundingCampaignV2.sol` contract. Let's start by reviewing the [`upgradeBeaconCrowdfundingCampaign.ts`](https://github.com/dutterbutter/zksync-quickstart-guide/blob/db/contract-upgrade/deploy/upgrade-scripts/upgradeBeaconCrowdfundingCampaign.ts) script in the `deploy/upgrade-scripts` directory: +Make sure to replace `YOUR_BEACON_ADDRESS_HERE` with the address of your deployed beacon and +`YOUR_PROXY_ADDRESS_HERE` with the actual address of your +deployed Beacon Proxy from the previous deployment step. + ```typescript import { getWallet } from "../utils"; import { Deployer } from '@matterlabs/hardhat-zksync'; @@ -337,7 +319,7 @@ export default async function (hre: HardhatRuntimeEnvironment) { // Placeholder for the deployed beacon address const beaconAddress = 'YOUR_BEACON_ADDRESS_HERE'; - + const contractV2Artifact = await deployer.loadArtifact('CrowdfundingCampaignV2'); // Upgrade the proxy to V2 @@ -351,7 +333,7 @@ export default async function (hre: HardhatRuntimeEnvironment) { deployer.zkWallet, deployer.deploymentType, ); - + // Placeholder for the deployed beacon proxy address const proxyAddress = 'YOUR_PROXY_ADDRESS_HERE'; @@ -370,10 +352,6 @@ export default async function (hre: HardhatRuntimeEnvironment) { } ``` -Ensure to replace `YOUR_BEACON_ADDRESS_HERE` with the address of your deployed beacon and -`YOUR_PROXY_ADDRESS_HERE` with the actual address of your -deployed Beacon Proxy from the previous deployment step. - **Key Components:** - **`upgradeBeacon`**: This method from the `hre.zkUpgrades` module is used to update the beacon contract @@ -384,7 +362,6 @@ variables or logic introduced in the `CrowdfundingCampaignV2`. Here, it's used to set a new campaign duration, seamlessly integrating new functionalities while retaining the existing contract state and funds. -#### Upgrade contract Execute the test command corresponding to your package manager: ::code-group @@ -407,8 +384,6 @@ bun run hardhat deploy-zksync --script upgrade-scripts/upgradeBeaconCrowdfunding :: -#### Expected Output - Upon successful deployment, you'll receive output detailing the upgrade process, including the new beacon address, and transaction hash: @@ -419,7 +394,7 @@ CrowdfundingCampaignV2 initialized! 0x5f3131c77fcac19390f5f644a3ad1f0e7719dee4b4 Fundraising goal: 100000000000000000 ``` -## Step 6: Verify upgradable contracts +## Verify upgradable contracts For the verification of our upgradable contracts, it's essential to utilize the proxy address that was specified in our upgrade script. @@ -446,8 +421,6 @@ bun run hardhat verify :: -#### Expected Output - Upon successful verification, you'll receive output detailing the verification process: ```bash diff --git a/content/10.quick-start/_upgrading/_beacon_proxy_contract_upgradability.md b/content/10.quick-start/_upgrading/_beacon_proxy_contract_upgradability.md index b10318f1..779f73a9 100644 --- a/content/10.quick-start/_upgrading/_beacon_proxy_contract_upgradability.md +++ b/content/10.quick-start/_upgrading/_beacon_proxy_contract_upgradability.md @@ -8,11 +8,11 @@ for centralized logic updates across multiple proxies. The structure includes: 1. **Beacon Contract**: Acts as the central point holding the address of the current logic contract. It enables updating the logic for all associated proxies through a single transaction. -2. **Proxy Contracts**: These lightweight contracts delegate calls to the logic contract address +1. **Proxy Contracts**: These lightweight contracts delegate calls to the logic contract address provided by the beacon, maintaining their own state and balance. -3. **Logic Contract**: Contains the executable business logic, which can be updated by changing +1. **Logic Contract**: Contains the executable business logic, which can be updated by changing the beacon's reference without altering individual proxies. -4. **Admin Address**: Authorized to update the logic contract address in the beacon, ensuring controlled and secure upgrades. +1. **Admin Address**: Authorized to update the logic contract address in the beacon, ensuring controlled and secure upgrades. This arrangement allows multiple proxy contracts to be upgraded simultaneously by updating the logic contract address in the beacon, streamlining the upgrade process. It preserves diff --git a/content/10.quick-start/_upgrading/_transparent/_hardhat_transparent_contract_upgradability.md b/content/10.quick-start/_upgrading/_transparent/_hardhat_transparent_contract_upgradability.md index 178d3e6a..9a4ae737 100644 --- a/content/10.quick-start/_upgrading/_transparent/_hardhat_transparent_contract_upgradability.md +++ b/content/10.quick-start/_upgrading/_transparent/_hardhat_transparent_contract_upgradability.md @@ -1,57 +1,43 @@ --- title: Hardhat | Contract Upgrading --- - -Hardhat is an Ethereum development environment, designed for easy smart contract development in Solidity. -zkSync provides its own plugins which makes working with contracts on zkSync simple and efficient. - -## Step 1: Setting up environment -:display-partial{path = "/_partials/_environment-setup-with-zksync-cli"} -::drop-panel - ::panel{label="Initialize project"} - Run the following command in your terminal to initialize the project. +Run the following command in your terminal to initialize the project. - ```sh - git clone https://github.com/dutterbutter/zksync-quickstart-guide.git - cd zksync-quickstart-guide - git checkout db/contract-upgrade - ``` - Install the dependencies: +```sh +git clone https://github.com/dutterbutter/zksync-quickstart-guide.git +cd zksync-quickstart-guide +git checkout db/contract-upgrade +``` - ::code-group +Install the dependencies: - ```bash [yarn] - yarn install - ``` +::code-group - ```bash [pnpm] - pnpm run install - ``` +```bash [yarn] +yarn install +``` - ```bash [npm] - npm run install - ``` +```bash [pnpm] +pnpm install +``` - ```bash [bun] - bun run install - ``` +```bash [npm] +npm install +``` - :: - :: -:: +```bash [bun] +bun install +``` -## Step 2: Set up wallet +:: -Deploying contracts on the zkSync Sepolia testnet requires having testnet ETH. -If you're working within the local development environment, -you can utilize pre-configured rich wallets and skip this step. -For testnet deployments, follow these steps to secure your funds: +## Set up your wallet -:display-partial{path = "/_partials/_environment-setup-with-zksync-cli"} +:display-partial{path = "/quick-start/_partials/_setup-wallet"} -## Step 3: Adapting `CrowdfundingCampaign.sol` contract for upgradability +## Adapt `CrowdfundingCampaign.sol` contract for upgradability To adapt our `CrowdfundingCampaign.sol` contract for upgradability, we're transitioning to a proxy pattern. This approach separates the @@ -116,7 +102,7 @@ allowing for future upgrades without losing the contract's state. This restructuring prepares the `CrowdfundingCampaign` contract for upgradability. -## Step 4: Deploy the `CrowdfundingCampaign` contract +## Deploy the `CrowdfundingCampaign` contract Now that the `CrowdfundingCampaign` contract is adapted for contract upgradability, let's proceed to deploy the contract so we may upgrade it in later steps. Since we've made changes to our contract we will @@ -144,8 +130,6 @@ bun run compile :: -#### Expected Output - Upon successful compilation, you'll receive output detailing the `zksolc` and `solc` versions used during compiling and the number of Solidity files compiled. @@ -195,7 +179,6 @@ This ensures the deployed contract can be upgraded in the future without losing - **`initializer`**: Specifies the initialization method of the contract, `initialize` in this case, which is required for setting up the proxy's state upon deployment. -#### Deploy contract Execute the deployment command corresponding to your package manager. The default command deploys to the configured network in your Hardhat setup. For local deployment, append `--network inMemoryNode` to deploy to the local in-memory node running. @@ -228,8 +211,6 @@ bun run hardhat deploy-zksync --script deployTransparentProxy.ts :: -#### Expected Output - Upon successful deployment, you'll receive output detailing the deployment process, including the contract addresses of the implementation contract, the admin contract, and the transparent @@ -241,7 +222,7 @@ Admin was deployed to 0x05198D9f93cBDfa3e332776019115512d8e0c809 Transparent proxy was deployed to 0x68E8533acE01019CB8D07Eca822369D5De71b74D ``` -## Step 5: Upgrading the `CrowdfundingCampaign` Contract +## Upgrade the `CrowdfundingCampaign` Contract With our initial setup deployed, we're ready to update our `CrowdfundingCampaign.sol` contract by incorporating a deadline for contributions. This addition not only brings @@ -295,8 +276,6 @@ exemplifies the use of `modifiers` for enforcing contract conditions. ### Compile contract :display-partial{path = "/_partials/_compile-solidity-contracts"} -#### Expected Output - Upon successful compilation, you'll receive output detailing the `zksolc` and `solc` versions used during compiling and the number of Solidity files compiled. @@ -316,6 +295,9 @@ to its second version, `CrowdfundingCampaignV2`. Review the [`upgradeCrowdfundingCampaign.ts`](https://github.com/dutterbutter/zksync-quickstart-guide/blob/db/contract-upgrade/deploy/upgrade-scripts/upgradeCrowdfundingCampaign.ts) script located within the `deploy/upgrade-scripts` directory to begin. +Ensure to replace `YOUR_PROXY_ADDRESS_HERE` with the actual address of your +deployed Transparent Proxy from the previous deployment step. + ```typescript import { getWallet } from "../utils"; import { Deployer } from '@matterlabs/hardhat-zksync'; @@ -324,10 +306,10 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; export default async function (hre: HardhatRuntimeEnvironment) { const wallet = getWallet(); const deployer = new Deployer(hre, wallet); - + // Placeholder for the deployed proxy address const proxyAddress = 'YOUR_PROXY_ADDRESS_HERE'; - + const contractV2Artifact = await deployer.loadArtifact('CrowdfundingCampaignV2'); // Upgrade the proxy to V2 @@ -338,7 +320,7 @@ export default async function (hre: HardhatRuntimeEnvironment) { upgradedContract.connect(deployer.zkWallet); // wait some time before the next call await new Promise((resolve) => setTimeout(resolve, 2000)); - + // Initialize V2 with a new campaign duration const durationInSeconds = 30 * 24 * 60 * 60; // For example, setting a 30-day duration const initTx = await upgradedContract.initializeV2(durationInSeconds); @@ -348,9 +330,6 @@ export default async function (hre: HardhatRuntimeEnvironment) { } ``` -Ensure to replace `YOUR_PROXY_ADDRESS_HERE` with the actual address of your -deployed Transparent Proxy from the previous deployment step. - **Key Components:** - **`upgradeProxy`:** A critical method from the `hre.zkUpgrades` module that @@ -362,7 +341,6 @@ variables or logic introduced in `CrowdfundingCampaignV2`. In this example, it sets a new campaign duration, illustrating how contract upgrades can add functionalities without losing the existing state or funds. -#### Upgrade contract Execute the command corresponding to your package manager: ::code-group @@ -385,8 +363,6 @@ bun run hardhat deploy-zksync --script upgrade-scripts/upgradeCrowdfundingCampai :: -#### Expected Output - Upon successful deployment, you'll receive output detailing the upgrade process, including the contract address, and transaction hash: @@ -397,13 +373,15 @@ CrowdfundingCampaignV2 initialized! 0x5adfe360187195d98d3603a82a20ffe7304cd4dec0 Fundraising goal: 100000000000000000 ``` -## Step 6: Verify upgradable contracts +## Verify upgradable contracts For the verification of our upgradable contracts, it's essential to utilize the proxy address that was specified in our upgrade script. To proceed with verification, execute the following command: +Replace with the actual proxy address from your deployment. + ::code-group ```bash [yarn] @@ -424,10 +402,6 @@ bun run hardhat verify :: -Ensure to replace with the actual proxy address from your deployment. - -#### Expected Output - Upon successful verification, you'll receive output detailing the verification process: ```bash diff --git a/content/10.quick-start/_upgrading/_transparent_proxy_contract_upgradability.md b/content/10.quick-start/_upgrading/_transparent_proxy_contract_upgradability.md index 70ac46e4..2f11aa06 100644 --- a/content/10.quick-start/_upgrading/_transparent_proxy_contract_upgradability.md +++ b/content/10.quick-start/_upgrading/_transparent_proxy_contract_upgradability.md @@ -8,8 +8,8 @@ logic updates while preventing accidental function collisions. They consist of: 1. **Proxy Contract**: Manages storage, balance, and delegates calls to the logic contract, except for those by the admin, ensuring clear separation between user and administrative interactions. -2. **Logic Contract**: Houses the actual business logic, upgradeable by swapping out for new versions. -3. **Admin Address**: Holds the rights to upgrade the logic contract, with its commands executed +1. **Logic Contract**: Houses the actual business logic, upgradeable by swapping out for new versions. +1. **Admin Address**: Holds the rights to upgrade the logic contract, with its commands executed exclusively by the proxy to prevent unintended logic execution. This setup ensures only non-administrative calls reach the logic contract, allowing diff --git a/content/10.quick-start/_upgrading/_uups/_hardhat_uups_contract_upgradability.md b/content/10.quick-start/_upgrading/_uups/_hardhat_uups_contract_upgradability.md index d36ec029..6c64a1b8 100644 --- a/content/10.quick-start/_upgrading/_uups/_hardhat_uups_contract_upgradability.md +++ b/content/10.quick-start/_upgrading/_uups/_hardhat_uups_contract_upgradability.md @@ -2,56 +2,41 @@ title: Hardhat | Contract Upgrading --- -Hardhat is an Ethereum development environment, designed for easy smart contract development in Solidity. -zkSync provides its own plugins which makes working with contracts on zkSync simple and efficient. - -## Step 1: Setting up environment -:display-partial{path = "/_partials/_environment-setup-with-zksync-cli"} -::drop-panel - ::panel{label="Initialize project"} - Run the following command in your terminal to initialize the project. - - ```sh - git clone https://github.com/dutterbutter/zksync-quickstart-guide.git - cd zksync-quickstart-guide - git checkout db/contract-upgrade - ``` - Install the dependencies: +Run the following command in your terminal to initialize the project. - ::code-group +```sh +git clone https://github.com/dutterbutter/zksync-quickstart-guide.git +cd zksync-quickstart-guide +git checkout db/contract-upgrade +``` - ```bash [yarn] - yarn install - ``` +Install the dependencies: - ```bash [pnpm] - pnpm run install - ``` +::code-group - ```bash [npm] - npm run install - ``` +```bash [yarn] +yarn install +``` - ```bash [bun] - bun run install - ``` +```bash [pnpm] +pnpm install +``` - :: - :: -:: +```bash [npm] +npm install +``` -## Step 2: Set up wallet +```bash [bun] +bun install +``` -Deploying contracts on the zkSync Sepolia testnet requires having testnet ETH. -If you're working within the local development environment, -you can utilize pre-configured rich wallets and skip this step. -For testnet deployments, follow these steps to secure your funds: +## Set up your wallet -:display-partial{path = "/_partials/_setting-up-your-wallet"} +:display-partial{path="quick-start/_partials/_setup-wallet"} -## Step 3: Adapting `CrowdfundingCampaign.sol` for UUPS Upgradability +## Adapt the `CrowdfundingCampaign.sol` for UUPS Upgradability To align the `CrowdfundingCampaign.sol` contract with UUPS (Universal Upgradeable Proxy Standard) upgradability, we're integrating OpenZeppelin's UUPSUpgradeable contracts. This method offers a more secure and gas-efficient @@ -123,7 +108,7 @@ reinforcing the contract's security. By adopting the UUPS pattern, the [`CrowdfundingCampaign_UUPS`](https://github.com/dutterbutter/zksync-quickstart-guide/blob/db/contract-upgrade/contracts/CrowdfundingCampaign_UUPS.sol) contract becomes efficiently upgradeable, offering enhanced security and reduced gas costs, setting a solid foundation for future enhancements. -## Step 4: Deploy the `CrowdfundingCampaign` contract +## Deploy the `CrowdfundingCampaign` contract Now that the `CrowdfundingCampaign_UUPS` contract is adapted for contract upgradability, let's proceed to deploy the contract so we may upgrade it in later steps. Since we've made changes to our contract we will @@ -151,8 +136,6 @@ bun run compile :: -#### Expected Output - Upon successful compilation, you'll receive output detailing the `zksolc` and `solc` versions used during compiling and the number of Solidity files compiled. @@ -205,7 +188,6 @@ The use of the UUPS pattern provides a secure and efficient mechanism for future This is used for setting up the initial state of the contract upon deployment, particularly important for upgradeable contracts where constructor usage is not possible. -#### Deploy contract Execute the deployment command corresponding to your package manager. The default command deploys to the configured network in your Hardhat setup. For local deployment, append `--network inMemoryNode` to deploy to the local in-memory node running. @@ -238,8 +220,6 @@ bun run hardhat deploy-zksync --script deployUUPS.ts :: -#### Expected Output - Upon successful deployment, you'll receive output detailing the deployment process, including the contract addresses of the implementation contract, the admin contract, and the transparent @@ -250,7 +230,7 @@ Implementation contract was deployed to 0xF0De77041F3cF6D9C905A10ce59858b17E57E3 UUPS proxy was deployed to 0x56882194aAe8E4B6d18cD84e4D7B0F807e0100Cb ``` -## Step 5: Upgrading the `CrowdfundingCampaign_UUPS` Contract +## Upgrade the `CrowdfundingCampaign_UUPS` Contract With our initial setup deployed, we're ready to upgrade our `CrowdfundingCampaign_UUPS.sol` contract by incorporating a deadline for contributions. This addition not only brings @@ -305,8 +285,6 @@ exemplifies the use of `modifiers` for enforcing contract conditions. :display-partial{path = "/_partials/_compile-solidity-contracts"} -#### Expected Output - Upon successful compilation, you'll receive output detailing the `zksolc` and `solc` versions used during compiling and the number of Solidity files compiled. @@ -325,6 +303,9 @@ This section describes the initiating the upgrade to `CrowdfundingCampaignV2_UUP Let's start by reviewing the [`upgradeUUPSCrowdfundingCampaign.ts`](https://github.com/dutterbutter/zksync-quickstart-guide/blob/db/contract-upgrade/deploy/upgrade-scripts/upgradeUUPSCrowdfundingCampaign.ts) script in the `deploy/upgrade-scripts` directory: +Replace `YOUR_PROXY_ADDRESS_HERE` with the actual address of your +deployed Transparent Proxy from the previous deployment step. + ```typescript import { getWallet } from "../utils"; import { Deployer } from '@matterlabs/hardhat-zksync'; @@ -336,7 +317,7 @@ export default async function (hre: HardhatRuntimeEnvironment) { // Placeholder for the deployed proxy address const proxyAddress = 'YOUR_PROXY_ADDRESS_HERE'; - + // Upgrade the proxy to V2 const contractV2Artifact = await deployer.loadArtifact('CrowdfundingCampaignV2_UUPS'); const upgradedContract = await hre.zkUpgrades.upgradeProxy(deployer.zkWallet, proxyAddress, contractV2Artifact); @@ -345,7 +326,7 @@ export default async function (hre: HardhatRuntimeEnvironment) { upgradedContract.connect(deployer.zkWallet); // wait some time before the next call await new Promise((resolve) => setTimeout(resolve, 2000)); - + const durationInSeconds = 30 * 24 * 60 * 60; // For example, setting a 30-day duration const initTx = await upgradedContract.initializeV2(durationInSeconds); @@ -355,9 +336,6 @@ export default async function (hre: HardhatRuntimeEnvironment) { } ``` -Ensure to replace `YOUR_PROXY_ADDRESS_HERE` with the actual address of your -deployed Transparent Proxy from the previous deployment step. - **Key Components:** - **`upgradeProxy`:** A critical method from the `hre.zkUpgrades` module that @@ -369,7 +347,6 @@ variables or logic introduced in `CrowdfundingCampaignV2_UUPS`. In this example, it sets a new campaign duration, illustrating how contract upgrades can add functionalities without losing the existing state or funds. -#### Upgrade contract Execute the test command corresponding to your package manager: ::code-group @@ -392,8 +369,6 @@ bun run hardhat deploy-zksync --script upgrade-scripts/upgradeUUPSCrowdfundingCa :: -#### Expected Output - Upon successful deployment, you'll receive output detailing the upgrade process, including the new beacon address, and transaction hash: @@ -403,7 +378,7 @@ Successfully upgraded crowdfundingCampaign_UUPS to crowdfundingCampaignV2_UUPS CrowdfundingCampaignV2_UUPS initialized! 0xab959f588b64dc6dee1e94d5fa0da2ae205c7438cf097d26d3ba73690e2b09e8 ``` -## Step 6: Verify upgradable contracts +## Verify upgradable contracts To verify our upgradable contracts we need to the proxy address we previously used in our upgrade script. With that execute the following command: diff --git a/content/10.quick-start/_upgrading/_uups_contract_upgradability.md b/content/10.quick-start/_upgrading/_uups_contract_upgradability.md index ad252b53..696b8d0c 100644 --- a/content/10.quick-start/_upgrading/_uups_contract_upgradability.md +++ b/content/10.quick-start/_upgrading/_uups_contract_upgradability.md @@ -8,9 +8,9 @@ within the contract itself, simplifying upgrades and enhancing security. The com 1. **Proxy Contract**: Contains minimal logic, primarily delegating calls to the implementation contract. Unlike other proxies, it doesn't require a separate upgrade function. -2. **Implementation Contract**: Houses the business logic and the upgrade functionality, +1. **Implementation Contract**: Houses the business logic and the upgrade functionality, enabling the contract to upgrade itself from within. -3. **Admin Role**: Assigned to an entity with the authority to initiate upgrades, ensuring +1. **Admin Role**: Assigned to an entity with the authority to initiate upgrades, ensuring controlled access to the upgrade function. In UUPS contracts, upgrades are performed by invoking the upgrade function within the diff --git a/content/_partials/_deploy-contract.md b/content/_partials/_deploy-contract.md deleted file mode 100644 index 7bea2ee7..00000000 --- a/content/_partials/_deploy-contract.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: Deploy Contract ---- - -::drop-panel - ::panel{label = "Deploy Contract"} - Deploying contracts on the zkSync Sepolia testnet requires having testnet ETH. - If you're working within the local development environment, - you can utilize pre-configured rich wallets and skip this step. - For testnet deployments, follow these steps to secure your funds: - - 1. Obtaining Testnet ETH: - - Use the [LearnWeb3 faucet](https://learnweb3.io/faucets/zksync_sepolia/) to directly receive testnet ETH on zkSync Sepolia. - - Alternatively, acquire SepoliaETH from [recommended faucets](https://www.notion.so/tooling/network-faucets.md) and transfer it to the zkSync Sepolia testnet via the [zkSync bridge](https://portal.zksync.io/bridge/?network=sepolia). - - 1. Verify your balance: - - Check your wallet's balance using the [zkSync Sepolia explorer](https://sepolia.explorer.zksync.io/). - :: -:: diff --git a/content/_partials/_environment-setup-with-foundry.md b/content/_partials/_environment-setup-with-foundry.md index 4e549072..7829370c 100644 --- a/content/_partials/_environment-setup-with-foundry.md +++ b/content/_partials/_environment-setup-with-foundry.md @@ -2,42 +2,16 @@ title: Foundry-zksync Installation --- -::drop-panel - ::panel{label="Install foundry-zksync"} - Begin by installing `foundry-zksync` in your environment using the command below: - - ``` - curl -L https://foundry-zksync.zksync.io | bash - ``` - :: - - ::panel{label="Setup local node (optional)"} - Leveraging **zksync-cli** to set up - a local development environment is a beneficial next step. - This local setup allows for quicker testing and debugging - processes without incurring testnet transaction costs. - - **Prerequisites:** - - **Docker Installation:** **zksync-cli**'s local environment relies on Docker. - Download the appropriate version from the Docker website. - If you're new to Docker, consider exploring the Docker getting started guide. - - 1. **Open Your Terminal:** Access it from the Applications folder or use Spotlight search (Command + Space). - 2. **Initialize Local zkSync Node:** - - Run the command: **npx zksync-cli@latest dev start** - - When prompted, choose β€œIn memory node” to deploy a local zkSync node in a Docker container. - 3. **Access Rich Accounts:** For pre-configured rich wallets, visit [era-test-node rich wallets](https://era.zksync.io/docs/tools/testing/era-test-node.html#use-pre-configured-rich-wallets). - 4. **Local Node URL:** Your local zkSync node is accessible at - **[http://127.0.0.1:8011](http://127.0.0.1:8011/)**, ready for deployment or testing purposes. - :: - - ::panel{label="Initialize project"} - Run the following command in your terminal to create a new Foundry project using `foundry-zksync`. +::callout{icon="i-heroicons-information-circle-16-solid" color="amber"} +`foundry-zksync` is still in an alpha stage, so some features might not be fully supported +yet and may not work as fully intended. It is open-sourced and contributions are welcomed. +:: + - ```sh - forge init --template https://github.com/dutterbutter/zksync-foundry-quickstart-guide - ``` +Run the following command in your terminal to create a new Foundry project using `foundry-zksync`. - :: -:: + ```sh + forge init --template https://github.com/dutterbutter/zksync-foundry-quickstart-guide + ``` diff --git a/content/_partials/_environment-setup-with-zksync-cli.md b/content/_partials/_environment-setup-with-zksync-cli.md deleted file mode 100644 index e22548a6..00000000 --- a/content/_partials/_environment-setup-with-zksync-cli.md +++ /dev/null @@ -1,39 +0,0 @@ ---- -title: Environment Setup With zkSync CLI ---- - -::drop-panel - ::panel{label="Install Node.js or Bun.sh"} - To effectively utilize the **zksync-cli** tool, your - development environment needs to be set up with either Node.js or Bun.sh. - The choice depends on your project's requirements and personal preference for package management and execution speed. - - - Node.js - - Download the Long-Term Support (LTS) version from the [official Node.js website](https://nodejs.org/en/download). - - For first-time users, the [Node.js usage guide](https://nodejs.org/api/synopsis.html#usage) offers comprehensive instructions on getting started. - - Bun.sh - - Obtain the latest version from the [Bun installation page](https://bun.sh/docs/installation). Bun.sh is known for its high performance and modern JavaScript features. - :: - - ::panel{label="Setup local node (optional)"} - After installing Node.js or Bun, leveraging **zksync-cli** to set up - a local development environment is a beneficial next step. - This local setup allows for quicker testing and debugging - processes without incurring testnet transaction costs. - - **Prerequisites:** - - **Docker Installation:** **zksync-cli**'s local environment relies on Docker. - Download the appropriate version from the [Docker website](https://docs.docker.com/engine/install/). - If you're new to Docker, consider exploring the Docker getting started guide. - - 1. **Open Your Terminal:** Access it from the Applications folder or use Spotlight search (Command + Space). - 2. **Initialize Local zkSync Node:** - - Run the command: **npx zksync-cli@latest dev start** - - When prompted, choose β€œIn memory node” to deploy a local zkSync node in a Docker container. - 3. **Access Rich Accounts:** For pre-configured rich wallets, visit [era-test-node rich wallets](https://era.zksync.io/docs/tools/testing/era-test-node.html#use-pre-configured-rich-wallets). - 4. **Local Node URL:** Your local zkSync node is accessible at - **[http://127.0.0.1:8011](http://127.0.0.1:8011/)**, ready for deployment or testing purposes. - :: - -:: diff --git a/content/_partials/_setting-up-your-wallet.md b/content/_partials/_setting-up-your-wallet.md deleted file mode 100644 index 9074cefd..00000000 --- a/content/_partials/_setting-up-your-wallet.md +++ /dev/null @@ -1,40 +0,0 @@ ---- -title: Setting up your wallet ---- - -::drop-panel - ::panel{label="Fund Wallet"} - - 1. Obtaining Testnet ETH: - - - Use the [LearnWeb3 faucet](https://learnweb3.io/faucets/zksync_sepolia/) - to directly receive testnet ETH on zkSync Sepolia. - - Alternatively, acquire SepoliaETH from [recommended faucets](https://www.notion.so/tooling/network-faucets.md) and - transfer it to the zkSync Sepolia testnet via the [zkSync bridge](https://portal.zksync.io/bridge/?network=sepolia). - - 1. Verify your balance: - - - Check your wallet's balance using the [zkSync Sepolia explorer](https://sepolia.explorer.zksync.io/). - :: - - ::panel{label="Configuring Your Wallet in the Project"} - To deploy contracts, you'll need to securely add your wallet's private key to the project environment: - - 1. **Extract Your Private Key:** - - Find your wallet's private key. For MetaMask users, here's how to - [export your wallet's private key](https://support.metamask.io/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key). - If you're in the local environment, use a private key from the available rich accounts. - - 1. **Prepare the Environment File:** - - Locate the **`.env-example`** file in your project directory. Rename this file to **`.env`**. - - 1. **Add Your Private Key:** - - Open the `.env` file and add your private key in the following format: - - ```sh - WALLET_PRIVATE_KEY=your_private_key_here - ``` - - - Replace **`your_private_key_here`** with your actual private key. - :: -::