diff --git a/content/10.quick-start/00.index.md b/content/10.quick-start/00.index.md index 6b58e6e4..563db34c 100644 --- a/content/10.quick-start/00.index.md +++ b/content/10.quick-start/00.index.md @@ -9,7 +9,7 @@ In this guide, we'll walk you through the process of creating and deploying a si By the end of the series, you will learn integral pieces that will help you become a great developer on zkSync! You will learn how to: -:check-icon Initialize a new project with zksync-cli +:check-icon Initialize a new project with zksync-cli. :check-icon Deploy contracts on zkSync Era using Hardhat or Foundry. @@ -19,9 +19,11 @@ help you become a great developer on zkSync! You will learn how to: :check-icon Implement a Paymaster to simplify transactions for your users. +--- + ## Install zksync-cli -Our Quickstart Guide series utilizes the `zksync-cli` to help you develop and interact with zkSync from your local machine. +Our Quickstart series utilizes the `zksync-cli` to help you develop and interact with zkSync from your local machine. @@ -43,9 +45,9 @@ If you are unfamiliar with both, choose Node.js. ### Setup era local node (optional) -Our Quick Start series will have you compile and deploy contracts to +Our Quickstart 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. +Alternatively, 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 @@ -68,6 +70,10 @@ 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. +Leave this terminal open and running as you build your projects. +When you are done running your local Era node, you can stop it with `Ctrl+C`. + +--- ## Choose Hardhat or Foundry @@ -95,6 +101,8 @@ Install `foundry-zksync` with the following command: 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. @@ -110,6 +118,8 @@ If you did not set up a local era node for development and plan to use zkSync Se - 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: @@ -131,10 +141,13 @@ To deploy contracts, you'll need to securely add your wallet's private key to th - 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. +- This setup provides you everything you need to build in zkSync. +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/10.hello-zksync.md b/content/10.quick-start/10.hello-zksync.md index 20f9e7a2..954d12be 100644 --- a/content/10.quick-start/10.hello-zksync.md +++ b/content/10.quick-start/10.hello-zksync.md @@ -3,7 +3,7 @@ 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 series, we'll walk you through the process +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 Initialize a new project with zkSync-cli. @@ -14,6 +14,14 @@ of creating and deploying a simple smart contract that creates a crowdfunding ca Let's dive in and start your developer journey on zkSync! +--- + +## Prerequisites + +This Quickstart series requires some initial setup of tools to elevate your +development experience building for zkSync. +Make sure to go through the setup provided in the initial [Getting Started](/quick-start) section. + Select the framework you want to get started using zkSync Era with. ::content-switcher @@ -41,7 +49,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](/quick-start/deploy-factory). This will allow you to efficiently +for the `CrowdfundingCampaign` contract in the [next guide](/quick-start/contract-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/20.deploy-factory.md b/content/10.quick-start/20.contract-factory.md similarity index 94% rename from content/10.quick-start/20.deploy-factory.md rename to content/10.quick-start/20.contract-factory.md index 2931f958..b9c23849 100644 --- a/content/10.quick-start/20.deploy-factory.md +++ b/content/10.quick-start/20.contract-factory.md @@ -1,9 +1,9 @@ --- -title: Contract Factories -description: Learn how to deploy and manage multiple smart contracts on zkSync using contract factories. +title: Contract Factory +description: Learn how to deploy and manage multiple smart contracts on zkSync using a contract factory. --- -This second quickstart installment advances from your introductory exploration of smart contract deployment to dive into the utility of 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. @@ -22,7 +22,9 @@ contract instances from a single "factory" contract. It's essentially a contract that creates other contracts, streamlining and organizing the deployment of numerous similar contracts efficiently. -## Framework selection +--- + +## Setup the project Select the framework you want to get started using zkSync Era with. diff --git a/content/10.quick-start/40.upgrading.md b/content/10.quick-start/40.upgrading.md index 53d5071e..fa798004 100644 --- a/content/10.quick-start/40.upgrading.md +++ b/content/10.quick-start/40.upgrading.md @@ -5,7 +5,7 @@ description: Learn to make smart contracts upgradeable within the zkSync ecosyst 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, **upgradeable**. +lead you through the strategies and practices for making the `CrowdfundingCampaign` contract **upgradeable**. :check-icon Harness advanced techniques for contract upgradability in zkSync. diff --git a/content/10.quick-start/50.paymaster.md b/content/10.quick-start/50.paymaster.md index 147ab275..67a97bed 100644 --- a/content/10.quick-start/50.paymaster.md +++ b/content/10.quick-start/50.paymaster.md @@ -43,6 +43,8 @@ As we explore paymasters, remember that while they offer enhanced flexibility fo 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 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 8a21c83b..94dad785 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 @@ -8,10 +8,11 @@ title: Foundry | Deploy Contract Factory :display-partial{path="quick-start/_partials/_setup-wallet"} +--- + ## Review the CrowdfundingFactory contract -With our environment and wallet configured, we're set to review the `CrowdfundingFactory.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` we will compile and deploy 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. @@ -62,7 +63,6 @@ making it efficient to launch and manage multiple campaigns. ### Compile contract - Smart contracts deployed to zkSync must be compiled using our custom compiler. For this particular guide we are making use of `zksolc`. @@ -72,8 +72,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. @@ -89,6 +87,8 @@ 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 a CrowdfundingCampaign with CrowdfundingFactory This section outlines the steps to deploy the `CrowdfundingCampaign` contract using 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 54fdaac0..5712ed41 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 @@ -33,13 +33,21 @@ bun install :: -## Deploy contract with factory +## Set up your wallet -With our environment and wallet configured, we're set to review the `CrowdfundingFactory.sol` +:display-partial{path="quick-start/_partials/_setup-wallet"} + +--- + +## Compile the contracts + +This section will focus on compiling and deploying the `CrowdfundingFactory.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. +This contract factory approach streamlines the deployment of crowdfunding campaigns, +making it efficient to launch and manage multiple campaigns. ::drop-panel ::panel{label="CrowdfundingFactory.sol"} @@ -83,11 +91,6 @@ deploys a new campaign contract with this goal, and tracks the created campaign created by the factory, allowing for easy access and management of multiple crowdfunding initiatives. -This contract factory approach streamlines the deployment of crowdfunding campaigns, -making it efficient to launch and manage multiple campaigns. - -### Compile contract - :display-partial{path = "/_partials/_compile-solidity-contracts"} Upon successful compilation, you'll receive output detailing the @@ -102,7 +105,7 @@ Successfully compiled 2 Solidity file The compiled artifacts will be located in the `/artifacts-zk` folder. -### Deploy via the CrowdfundingFactory +### Deploy CrowdfundingCampaigns via the CrowdfundingFactory This section outlines the steps to deploy the `CrowdfundingCampaign` contract using our new `CrowdfundingFactory`. @@ -156,7 +159,7 @@ The deployment script is located at `/deploy/deployUsingFactory.ts`. - 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 +Run the deployment command. 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. diff --git a/content/10.quick-start/_hello-zksync/_foundry_deploy_contract.md b/content/10.quick-start/_hello-zksync/_foundry_deploy_contract.md index eaa05010..51380e35 100644 --- a/content/10.quick-start/_hello-zksync/_foundry_deploy_contract.md +++ b/content/10.quick-start/_hello-zksync/_foundry_deploy_contract.md @@ -8,9 +8,9 @@ title: Foundry | Deploy Contract :display-partial{path = "/quick-start/_partials/_setup-wallet"} -## Deploy your first contract +## Compile your first contract -With our environment and wallet configured, we're set to deploy our first contract. This guide +This guide introduces a crowdfunding campaign contract aimed at supporting Zeek's inventive ventures. Let's start by reviewing the starter contract in the [`src/` directory](https://github.com/dutterbutter/zksync-foundry-quickstart-guide/blob/main/src/Crowdfund.sol). @@ -77,8 +77,6 @@ Owned and deployed with a set funding goal, it features: - The `contribute` method to log funds, triggering `ContributionReceived` and `GoalReached` events. - The `withdrawFunds` method, allowing the owner to collect accumulated funds post-goal achievement. -### Compile contract - Smart contracts deployed to zkSync must be compiled using our custom compiler. For this particular guide we are making use of `zksolc`. @@ -103,9 +101,8 @@ 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 the CrowdfundingCampaign contract -This section outlines the steps to deploy the `CrowdfundingCampaign` contract. The deployment script is located at [`/script/Deploy.s.sol`](https://github.com/dutterbutter/zksync-foundry-quickstart-guide/blob/main/script/Deploy.s.sol). ```solidity @@ -135,8 +132,6 @@ a single constructor argument, `fundingGoalInWei`. - **Broadcast Method:** The deployment uses `vm.startBroadcast(deployerPrivateKey)` to begin the transaction broadcast and `vm.stopBroadcast()` to end it, facilitating the actual deployment of the contract on the blockchain. -#### Deploy contract - Execute the deployment command. ```bash diff --git a/content/10.quick-start/_hello-zksync/_hardhat_deploy_contract.md b/content/10.quick-start/_hello-zksync/_hardhat_deploy_contract.md index 5d4b5d0d..73247d8f 100644 --- a/content/10.quick-start/_hello-zksync/_hardhat_deploy_contract.md +++ b/content/10.quick-start/_hello-zksync/_hardhat_deploy_contract.md @@ -38,9 +38,8 @@ bun install :display-partial{path="quick-start/_partials/_setup-wallet"} -## Deploy the CrowdfundingCampaign.sol contract +## Compile 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. Let's start by reviewing the starter contract in the [`contracts/` directory](https://github.com/dutterbutter/zksync-quickstart-guide/blob/main/contracts/Crowdfund.sol). @@ -106,12 +105,8 @@ This contract features: - The `contribute` method to log funds, triggering `ContributionReceived` and `GoalReached` events. - The `withdrawFunds` method, allowing the owner to collect accumulated funds post-goal achievement. -### 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. @@ -124,9 +119,8 @@ Successfully compiled 1 Solidity file The compiled artifacts will be located in the `/artifacts-zk` folder. -### Deploy +## Deploy the contract -This section outlines the steps to deploy the `CrowdfundingCampaign` contract. The deployment script is located at [`/deploy/deploy.ts`](https://github.com/dutterbutter/zksync-quickstart-guide/blob/main/deploy/deploy.ts). ```typescript @@ -148,8 +142,7 @@ export default async function () { - **constructorArguments:** Sets initialization parameters for the contract. In this case, the fundraising goal, converted from ether to `wei` to match Solidity's `uint256` type. -#### Deploy contract -Execute the deployment command corresponding to your package manager. The default command +1. 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. @@ -181,8 +174,6 @@ bun run hardhat deploy-zksync --script deploy.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/_paymasters/_approval_paymaster_flow.md b/content/10.quick-start/_paymasters/_approval_paymaster_flow.md index 7239e96c..2d0b80fe 100644 --- a/content/10.quick-start/_paymasters/_approval_paymaster_flow.md +++ b/content/10.quick-start/_paymasters/_approval_paymaster_flow.md @@ -40,7 +40,9 @@ bun install :display-partial{path = "/quick-start/_partials/_setup-wallet"} -## Understanding the ApprovalPaymaster contract +--- + +## Understanding the `ApprovalPaymaster` contract Let's start by reviewing the `ApprovalPaymaster.sol` contract in the `contracts/` directory: @@ -138,7 +140,9 @@ 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. -## Deploy ApprovalPaymaster contract +--- + +## Compile and deploy the `ApprovalPaymaster` contract :display-partial{path = "/_partials/_compile-solidity-contracts"} @@ -154,12 +158,7 @@ Successfully compiled 1 Solidity file 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 of the `CrowdfundingCampaign` contract. -Deploying the `GaslessPaymaster` contract is the same. - -The deployment script is located at `/deploy/deploy.ts`. +The script to deploy the `GaslessPaymaster` contract is located at `/deploy/deploy.ts`. ```typescript import { deployContract, getWallet, getProvider } from "./utils"; @@ -250,83 +249,91 @@ Contract successfully verified on zkSync block explorer! Paymaster ETH balance is now 5000000000000000 ``` -## Interact with the ApprovalPaymaster contract +--- + +## Interact with the `ApprovalPaymaster` 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. +This section will navigate you through the steps to interact with the `GaslessPaymaster` contract, +using it to cover transaction fees for your 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"; -import { ethers } from "ethers"; -import { utils } from "zksync-ethers"; - -// Address of the contract to interact with -const CONTRACT_ADDRESS = "YOUR-CONTRACT-ADDRESS"; -const PAYMASTER_ADDRESS = "YOUR-PAYMASTER-ADDRESS"; -if (!CONTRACT_ADDRESS || !PAYMASTER_ADDRESS) - throw new Error("Contract and Paymaster addresses are required."); - -export default async function() { - console.log(`Running script to interact with contract ${CONTRACT_ADDRESS} using paymaster ${PAYMASTER_ADDRESS}`); - - // Load compiled contract info - const contractArtifact = await hre.artifacts.readArtifact( - "CrowdfundingCampaignV2" - ); - - // Initialize contract instance for interaction - const contract = new ethers.Contract( - CONTRACT_ADDRESS, - contractArtifact.abi, - getWallet() - ); - - const provider = getProvider(); - let balanceBeforeTransaction = await provider.getBalance(getWallet().address); - console.log(`Wallet balance before contribution: ${ethers.formatEther(balanceBeforeTransaction)} ETH`); - - const contributionAmount = ethers.parseEther("0.01"); - // Get paymaster params - const paymasterParams = utils.getPaymasterParams(PAYMASTER_ADDRESS, { - type: "General", - innerInput: new Uint8Array(), - }); - - const gasLimit = await contract.contribute.estimateGas({ - value: contributionAmount, - customData: { - gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT, - paymasterParams: paymasterParams, - }, - }); - - const transaction = await contract.contribute({ - value: contributionAmount, - maxPriorityFeePerGas: 0n, - maxFeePerGas: await provider.getGasPrice(), - gasLimit, - // Pass the paymaster params as custom data - customData: { - gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT, - paymasterParams, - }, - }); - 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 - // Gas fees are covered by the paymaster - console.log(`Wallet balance after contribution: ${ethers.formatEther(balanceAfterTransaction)} ETH`); -} -``` +::drop-panel + ::panel{label="interactWithPaymaster.ts"} + + ```typescript + import * as hre from "hardhat"; + import { getWallet, getProvider } from "../utils"; + import { ethers } from "ethers"; + import { utils } from "zksync-ethers"; + + // Address of the contract to interact with + const CONTRACT_ADDRESS = "YOUR-CONTRACT-ADDRESS"; + const PAYMASTER_ADDRESS = "YOUR-PAYMASTER-ADDRESS"; + if (!CONTRACT_ADDRESS || !PAYMASTER_ADDRESS) + throw new Error("Contract and Paymaster addresses are required."); + + export default async function() { + console.log(`Running script to interact with contract ${CONTRACT_ADDRESS} using paymaster ${PAYMASTER_ADDRESS}`); + + // Load compiled contract info + const contractArtifact = await hre.artifacts.readArtifact( + "CrowdfundingCampaignV2" + ); + + // Initialize contract instance for interaction + const contract = new ethers.Contract( + CONTRACT_ADDRESS, + contractArtifact.abi, + getWallet() + ); + + const provider = getProvider(); + let balanceBeforeTransaction = await provider.getBalance(getWallet().address); + console.log(`Wallet balance before contribution: ${ethers.formatEther(balanceBeforeTransaction)} ETH`); + + const contributionAmount = ethers.parseEther("0.01"); + // Get paymaster params + const paymasterParams = utils.getPaymasterParams(PAYMASTER_ADDRESS, { + type: "General", + innerInput: new Uint8Array(), + }); + + const gasLimit = await contract.contribute.estimateGas({ + value: contributionAmount, + customData: { + gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT, + paymasterParams: paymasterParams, + }, + }); + + const transaction = await contract.contribute({ + value: contributionAmount, + maxPriorityFeePerGas: 0n, + maxFeePerGas: await provider.getGasPrice(), + gasLimit, + // Pass the paymaster params as custom data + customData: { + gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT, + paymasterParams, + }, + }); + 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 + // Gas fees are covered by the paymaster + console.log(`Wallet balance after contribution: ${ethers.formatEther(balanceAfterTransaction)} ETH`); + } + ``` + + :: +:: **Key Components:** @@ -338,8 +345,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 diff --git a/content/10.quick-start/_paymasters/_general_paymaster_flow.md b/content/10.quick-start/_paymasters/_general_paymaster_flow.md index 682c9dda..fd0538e9 100644 --- a/content/10.quick-start/_paymasters/_general_paymaster_flow.md +++ b/content/10.quick-start/_paymasters/_general_paymaster_flow.md @@ -39,7 +39,9 @@ bun install :display-partial{path = "/quick-start/_partials/_setup-wallet"} -## Understanding GeneralPaymaster contract +--- + +## Understanding the `GeneralPaymaster` contract Let's start by reviewing the `GeneralPaymaster.sol` contract in the `contracts/` directory: @@ -141,7 +143,9 @@ 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. -## Deploy the GeneralPaymaster contract +--- + +## Compile and deploy the `GeneralPaymaster` contract :display-partial{path = "/_partials/_compile-solidity-contracts"} @@ -157,12 +161,7 @@ Successfully compiled 4 Solidity file 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. -Deploying the `GaslessPaymaster` contract is the same. - -The deployment script is located at `/deploy/deploy.ts`. +The script to deploy the `GaslessPaymaster` is located at `/deploy/deploy.ts`. ```typescript import { deployContract, getWallet, getProvider } from "./utils"; @@ -253,10 +252,12 @@ Contract successfully verified on zkSync block explorer! Paymaster ETH balance is now 5000000000000000 ``` +--- + ## 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. +This section will navigate you through the steps to interact with the `GeneralPaymaster` contract, +using it to cover transaction fees for your operation. The interaction script is situated in the `/deploy/interact/` directory, named `interactWithPaymaster.ts`. diff --git a/content/10.quick-start/_testing/_foundry_contract_testing.md b/content/10.quick-start/_testing/_foundry_contract_testing.md index bfc523a3..a1e91af5 100644 --- a/content/10.quick-start/_testing/_foundry_contract_testing.md +++ b/content/10.quick-start/_testing/_foundry_contract_testing.md @@ -4,6 +4,8 @@ title: Hardhat | Contract Testing :display-partial{path = "/_partials/_environment-setup-with-foundry"} +--- + ## Test the `CrowdfundingCampaign` contract Now that our setup is complete, it's time to focus on the core of this @@ -177,8 +179,6 @@ 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. -#### Run the tests - Execute the test command: ```bash diff --git a/content/10.quick-start/_testing/_hardhat_contract_testing.md b/content/10.quick-start/_testing/_hardhat_contract_testing.md index 5eeec7b9..d4d609e5 100644 --- a/content/10.quick-start/_testing/_hardhat_contract_testing.md +++ b/content/10.quick-start/_testing/_hardhat_contract_testing.md @@ -33,7 +33,9 @@ Run the following command in your terminal to initialize the project. :: -### Local Era Node +--- + +## 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, @@ -64,7 +66,7 @@ toolkit available for your project. import "@nomicfoundation/hardhat-chai-matchers"; ``` -## Test Wallet Configuration +### Test Wallet Configuration 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: @@ -74,7 +76,9 @@ which eliminates the need for manual funding or setup: This streamlined approach allows us to focus on writing and running effective tests. -## Test `CrowdfundingCampaign` contract +--- + +## Compile 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 @@ -144,8 +148,6 @@ consider writing additional tests for the `withdrawFunds`, `getTotalFundsRaised` and `getFundingGoal` methods, expanding your test coverage and reinforcing the reliability of the contract. -### Compile contract - :display-partial{path = "/_partials/_compile-solidity-contracts"} Upon successful compilation, you'll receive output detailing the @@ -160,7 +162,9 @@ Successfully compiled 2 Solidity file The compiled artifacts will be located in the `/artifacts-zk` folder. -### Testing +--- + +## Test `CrowdfundingCampaign` This section describes testing the `CrowdfundingCampaign.sol` contract. Let's start by reviewing the tests for `CrowdfundingCampaign.sol` contract provided @@ -218,7 +222,6 @@ 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. -#### Run the tests Execute the test command corresponding to your package manager: ::code-group 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 991b64e3..d60ac052 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 @@ -38,6 +38,8 @@ bun install :display-partial{path = "/quick-start/_partials/_setup-wallet"} +--- + ## Adapt `CrowdfundingCampaign.sol` contract for upgradability To adapt our `CrowdfundingCampaign.sol` contract for upgradability, we are @@ -45,8 +47,6 @@ transitioning to a proxy pattern. This approach separates the contract's logic (which can be upgraded) from its persistent state (stored in the proxy). -### Refactoring for Proxy Compatibility - In the `contracts/` directory you'll observe the refactored the [`CrowdfundingCampaign` contract](https://github.com/dutterbutter/zksync-quickstart-guide/blob/db/contract-upgrade/contracts/CrowdfundingCampaign.sol) which initializes state variables through an `initialize` function instead of the constructor, in line with the proxy pattern. @@ -102,7 +102,9 @@ allowing for future upgrades without losing the contract's state. This restructuring prepares the `CrowdfundingCampaign` contract for upgradeability. -## Deploy the `CrowdfundingCampaign` contract +--- + +## Compile the updated `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 @@ -142,7 +144,7 @@ Successfully compiled 3 Solidity file The compiled artifacts will be located in the `/artifacts-zk` folder. -### Deploy +## Deploy the beacon and contract 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). @@ -228,7 +230,9 @@ Beacon deployed at: 0x26410Bebf5Df7398DCBC5f00e9EBBa0Ddf471C72 Beacon proxy deployed at: 0xD58FA9Fb362Abf69cFc68A3545fD227165DAc167 ``` -## Upgrade the `CrowdfundingCampaign` Contract +--- + +## Compile the `CrowdfundingCampaignV2` 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 @@ -296,7 +300,7 @@ Successfully compiled 4 Solidity file The compiled artifacts will be located in the `/artifacts-zk` folder. -### Upgrading to `CrowdfundingCampaignV2` +## Upgrade to `CrowdfundingCampaignV2` 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) @@ -394,6 +398,8 @@ CrowdfundingCampaignV2 initialized! 0x5f3131c77fcac19390f5f644a3ad1f0e7719dee4b4 Fundraising goal: 100000000000000000 ``` +--- + ## Verify upgradable contracts For the verification of our upgradable contracts, it's essential to utilize the proxy address that was specified in our 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 779f73a9..0c10b584 100644 --- a/content/10.quick-start/_upgrading/_beacon_proxy_contract_upgradability.md +++ b/content/10.quick-start/_upgrading/_beacon_proxy_contract_upgradability.md @@ -19,6 +19,8 @@ the logic contract address in the beacon, streamlining the upgrade process. It p the state and balance of each proxy contract, offering an efficient way to roll out new features or fixes while maintaining a uniform interface for users. +--- + ::content-switcher --- items: [{ 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 9a4ae737..3136e6b1 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 @@ -33,10 +33,14 @@ bun install :: +--- + ## Set up your wallet :display-partial{path = "/quick-start/_partials/_setup-wallet"} +--- + ## Adapt `CrowdfundingCampaign.sol` contract for upgradability To adapt our `CrowdfundingCampaign.sol` contract for upgradability, we're @@ -102,6 +106,8 @@ allowing for future upgrades without losing the contract's state. This restructuring prepares the `CrowdfundingCampaign` contract for upgradability. +--- + ## Deploy the `CrowdfundingCampaign` contract Now that the `CrowdfundingCampaign` contract is adapted for contract upgradability, let's proceed to deploy @@ -142,9 +148,6 @@ Successfully compiled 3 Solidity file The compiled artifacts will be located in the `/artifacts-zk` folder. -### Deploy - -This section outlines the steps to deploy the `CrowdfundingCampaign` contract that we recently updated for upgradability. The deployment script is located at [`/deploy/deployTransparentProxy.ts`](https://github.com/dutterbutter/zksync-quickstart-guide/blob/db/contract-upgrade/deploy/deployTransparentProxy.ts). ```typescript @@ -222,6 +225,8 @@ Admin was deployed to 0x05198D9f93cBDfa3e332776019115512d8e0c809 Transparent proxy was deployed to 0x68E8533acE01019CB8D07Eca822369D5De71b74D ``` +--- + ## Upgrade the `CrowdfundingCampaign` Contract With our initial setup deployed, we're ready to update our `CrowdfundingCampaign.sol` @@ -272,6 +277,7 @@ 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"} @@ -288,14 +294,14 @@ Successfully compiled 4 Solidity file The compiled artifacts will be located in the `/artifacts-zk` folder. -### Upgrading to `CrowdfundingCampaignV2` +### Upgrade to `CrowdfundingCampaignV2` This section guides you through upgrading the `CrowdfundingCampaign` contract 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 +Replace `YOUR_PROXY_ADDRESS_HERE` with the actual address of your deployed Transparent Proxy from the previous deployment step. ```typescript @@ -373,6 +379,8 @@ CrowdfundingCampaignV2 initialized! 0x5adfe360187195d98d3603a82a20ffe7304cd4dec0 Fundraising goal: 100000000000000000 ``` +--- + ## Verify upgradable contracts For the verification of our upgradable contracts, it's essential to utilize the proxy address that was specified in our 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 2f11aa06..e9cfbbe3 100644 --- a/content/10.quick-start/_upgrading/_transparent_proxy_contract_upgradability.md +++ b/content/10.quick-start/_upgrading/_transparent_proxy_contract_upgradability.md @@ -18,9 +18,7 @@ while keeping the original proxy intact, the contract's state and balance are pr This facilitates improvements or bug fixes without changing the proxy, maintaining a consistent user interface. -## Framework selection - -Select the framework you want to get started using zkSync Era with. +--- ::content-switcher --- 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 6c64a1b8..e6dbf96f 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 @@ -32,10 +32,14 @@ npm install bun install ``` +:: + ## Set up your wallet :display-partial{path="quick-start/_partials/_setup-wallet"} +--- + ## Adapt the `CrowdfundingCampaign.sol` for UUPS Upgradability To align the `CrowdfundingCampaign.sol` contract with UUPS (Universal Upgradeable Proxy Standard) upgradability, @@ -108,7 +112,9 @@ 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. -## Deploy the `CrowdfundingCampaign` contract +--- + +## Compile the `CrowdfundingCampaign_UUPS` 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 @@ -148,10 +154,9 @@ Successfully compiled 4 Solidity file The compiled artifacts will be located in the `/artifacts-zk` folder. -### Deploy +## Deploy the updated contract -This section outlines the steps to deploy the `CrowdfundingCampaign_UUPS` contract that we recently updated for -UUPS upgradability. The deployment script is located at [`/deploy/deployUUPS.ts`](https://github.com/dutterbutter/zksync-quickstart-guide/blob/db/contract-upgrade/deploy/deployUUPS.ts). +The script to deploy the `CrowdfundingCampaign_UUPS` contract is located at [`/deploy/deployUUPS.ts`](https://github.com/dutterbutter/zksync-quickstart-guide/blob/db/contract-upgrade/deploy/deployUUPS.ts). ```typescript import { getWallet } from "./utils"; @@ -230,7 +235,9 @@ Implementation contract was deployed to 0xF0De77041F3cF6D9C905A10ce59858b17E57E3 UUPS proxy was deployed to 0x56882194aAe8E4B6d18cD84e4D7B0F807e0100Cb ``` -## Upgrade the `CrowdfundingCampaign_UUPS` Contract +--- + +## Upgrade to the `CrowdfundingCampaignV2_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 @@ -281,7 +288,7 @@ 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 +### Compile the `CrowdfundingCampaignV2_UUPS` contract :display-partial{path = "/_partials/_compile-solidity-contracts"} @@ -297,7 +304,7 @@ Successfully compiled 4 Solidity file The compiled artifacts will be located in the `/artifacts-zk` folder. -### Upgrading to `CrowdfundingCampaignV2_UUPS` +### Upgrade to `CrowdfundingCampaignV2_UUPS` This section describes the initiating the upgrade to `CrowdfundingCampaignV2_UUPS.sol` contract. Let's start by reviewing the [`upgradeUUPSCrowdfundingCampaign.ts`](https://github.com/dutterbutter/zksync-quickstart-guide/blob/db/contract-upgrade/deploy/upgrade-scripts/upgradeUUPSCrowdfundingCampaign.ts) @@ -378,6 +385,8 @@ Successfully upgraded crowdfundingCampaign_UUPS to crowdfundingCampaignV2_UUPS CrowdfundingCampaignV2_UUPS initialized! 0xab959f588b64dc6dee1e94d5fa0da2ae205c7438cf097d26d3ba73690e2b09e8 ``` +--- + ## Verify upgradable contracts To verify our upgradable contracts we need to the proxy address we previously used in our upgrade script. @@ -403,8 +412,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/_uups_contract_upgradability.md b/content/10.quick-start/_upgrading/_uups_contract_upgradability.md index 696b8d0c..44c6049a 100644 --- a/content/10.quick-start/_upgrading/_uups_contract_upgradability.md +++ b/content/10.quick-start/_upgrading/_uups_contract_upgradability.md @@ -20,6 +20,8 @@ implementation contract's built-in upgrade mechanism ensures only authorized upg The contract's state remains intact across upgrades, facilitating continuous improvement with a stable user experience. +--- + ::content-switcher --- items: [{ diff --git a/content/_partials/_compile-solidity-contracts.md b/content/_partials/_compile-solidity-contracts.md index edd54343..18afb51b 100644 --- a/content/_partials/_compile-solidity-contracts.md +++ b/content/_partials/_compile-solidity-contracts.md @@ -3,9 +3,9 @@ title: Compile Solidity Contract --- Smart contracts deployed to zkSync must be compiled using our custom compiler. -For this particular guide we are making use of `zksolc`. +`zksolc` is the compiler used for Solidity. -To compile the contracts in the project, run the following command: +To compile the contracts in a project, run the following command: ::code-group