Skip to content

Commit

Permalink
chore: clean up content and add links
Browse files Browse the repository at this point in the history
  • Loading branch information
dutterbutter committed Apr 12, 2024
1 parent ce4c22c commit 6f863e9
Show file tree
Hide file tree
Showing 16 changed files with 454 additions and 463 deletions.
2 changes: 1 addition & 1 deletion content/10.quick-start/1.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Learn to deploy smart contracts efficiently in the zkSync environme
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.

:check-icon Initializing a new project with a scaffolding tool.
:check-icon Initializing a new project with zkSync-cli.

:check-icon Crafting a smart contract to fund Zeek's latest adventure.

Expand Down
13 changes: 5 additions & 8 deletions content/10.quick-start/2.deploy_factory.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
---
title: Contract Factories
description: Learn to deploy contract factories in the zkSync environment.
description: Learn how to deploy and manage crowdfunding smart contracts on zkSync using contract factories.
---

Welcome back to the Quickstart Series on becoming proficient with zkSync development!
This second 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.
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 Constructing a contract factory to create multiple crowdfunding campaigns for Zeek.
:check-icon Constructing a contract factory to create multiple crowdfunding campaigns.

:check-icon Seamlessly deploying your contract factory on zkSync Era, using either Hardhat or Foundry.

Expand Down
2 changes: 1 addition & 1 deletion content/10.quick-start/3.testing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Testing
description: Learn to test smart contracts efficiently in the zkSync environment.
description: Discover how to effectively test smart contracts on zkSync Era ecosystem.
---

Welcome back to our Quickstart Series, your fast-track to zkSync development! In this
Expand Down
3 changes: 0 additions & 3 deletions content/10.quick-start/5.paymaster.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,4 @@ items: [{

## Next steps

With the contract factory in your zkSync development arsenal, you're set to elevate
your smart contract projects. Here's how you can further your journey:

-
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,40 @@ For testnet deployments, follow these steps to secure your funds:
## Step 3: Deploying 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 `/src` directory.
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).

The `CrowdfundingFactory.sol`contract will be used to deploy multiple instances of
the `CrowdfundingCampaign.sol` contract from the previous guide.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
::drop-panel
::panel{label="CrowdfundingFactory.sol"}
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// Crowdfunding campaign contract
import "./CrowdfundingCampaign.sol";
// Crowdfunding campaign contract
import "./CrowdfundingCampaign.sol";

// Factory contract to create and manage crowdfunding campaigns
contract CrowdfundingFactory {
CrowdfundingCampaign[] public campaigns;
// Factory contract to create and manage crowdfunding campaigns
contract CrowdfundingFactory {
CrowdfundingCampaign[] public campaigns;

event CampaignCreated(address campaignAddress, uint256 fundingGoal);
event CampaignCreated(address campaignAddress, uint256 fundingGoal);

function createCampaign(uint256 fundingGoal) public {
CrowdfundingCampaign newCampaign = new CrowdfundingCampaign(fundingGoal);
campaigns.push(newCampaign);
function createCampaign(uint256 fundingGoal) public {
CrowdfundingCampaign newCampaign = new CrowdfundingCampaign(fundingGoal);
campaigns.push(newCampaign);

emit CampaignCreated(address(newCampaign), fundingGoal);
}
emit CampaignCreated(address(newCampaign), fundingGoal);
}

function getCampaigns() public view returns (CrowdfundingCampaign[] memory) {
return campaigns;
function getCampaigns() public view returns (CrowdfundingCampaign[] memory) {
return campaigns;
}
}
}
```
```
::
::

The `CrowdfundingFactory` contract automates the creation and oversight of
`CrowdfundingCampaign` contracts, each with its distinct funding goals, it features:
Expand All @@ -71,10 +76,11 @@ created by the factory, allowing for easy access and management of multiple crow
initiatives.

This contract factory approach streamlines the deployment of crowdfunding campaigns,
making it efficient to launch and manage multiple campaigns concurrently.
making it efficient to launch and manage multiple campaigns.

### Compile contract

<!-- :display-partial{path = "/_partials/_compile-solidity-contracts-foundry"} -->
Smart contracts deployed to zkSync must be compiled using our custom compiler.
For this particular guide we are making use of `zksolc`.

Expand All @@ -92,8 +98,8 @@ of Solidity files compiled.

```bash
[⠒] Compiling...
[⠃] Compiling 22 files with 0.8.20
[⠊] Solc 0.8.20 finished in 736.48ms
[⠃] Compiling 3 files with 0.8.20
[⠊] Solc 0.8.20 finished in 336.48ms
Compiler run successful!
Compiling contracts for zkSync Era with zksolc v1.4.0
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contracts on zkSync simple and efficient.

## Step 1: Setting up environment
:display-partial{path = "/_partials/_environment-setup-with-zksync-cli"}
<!-- TODO: @dutterbutter determine best approach to leverate zksync cli for project
<!-- TODO: @dutterbutter determine best approach to leverage zksync cli for project
bootstrapping for this guide series. -->
::drop-panel
::panel{label="Initialize project"}
Expand Down Expand Up @@ -55,35 +55,40 @@ For testnet deployments, follow these steps to secure your funds:
## Step 3: Deploying 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.
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).

The `CrowdfundingFactory.sol`contract will be used to deploy multiple instances of
the `CrowdfundingCampaign.sol` contract from the previous guide.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
::drop-panel
::panel{label="CrowdfundingFactory.sol"}
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// Crowdfunding campaign contract
import "./CrowdfundingCampaign.sol";
// Crowdfunding campaign contract
import "./CrowdfundingCampaign.sol";

// Factory contract to create and manage crowdfunding campaigns
contract CrowdfundingFactory {
CrowdfundingCampaign[] public campaigns;
// Factory contract to create and manage crowdfunding campaigns
contract CrowdfundingFactory {
CrowdfundingCampaign[] public campaigns;

event CampaignCreated(address campaignAddress, uint256 fundingGoal);
event CampaignCreated(address campaignAddress, uint256 fundingGoal);

function createCampaign(uint256 fundingGoal) public {
CrowdfundingCampaign newCampaign = new CrowdfundingCampaign(fundingGoal);
campaigns.push(newCampaign);
function createCampaign(uint256 fundingGoal) public {
CrowdfundingCampaign newCampaign = new CrowdfundingCampaign(fundingGoal);
campaigns.push(newCampaign);

emit CampaignCreated(address(newCampaign), fundingGoal);
}
emit CampaignCreated(address(newCampaign), fundingGoal);
}

function getCampaigns() public view returns (CrowdfundingCampaign[] memory) {
return campaigns;
function getCampaigns() public view returns (CrowdfundingCampaign[] memory) {
return campaigns;
}
}
}
```
```
::
::

The `CrowdfundingFactory` contract automates the creation and oversight of
`CrowdfundingCampaign` contracts, each with its distinct funding goals, it features:
Expand All @@ -97,34 +102,11 @@ created by the factory, allowing for easy access and management of multiple crow
initiatives.

This contract factory approach streamlines the deployment of crowdfunding campaigns,
making it efficient to launch and manage multiple campaigns concurrently.
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`.

To compile the contracts in the project, run the following command:

::code-group

```bash [yarn]
yarn compile
```

```bash [pnpm]
pnpm run compile
```

```bash [npm]
npm run compile
```

```bash [bun]
bun run compile
```

::
:display-partial{path = "/_partials/_compile-solidity-contracts"}

#### Expected Output

Expand Down
92 changes: 50 additions & 42 deletions content/10.quick-start/_index/_foundry_deploy_contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,59 +29,64 @@ For testnet deployments, follow these steps to secure your funds:
## Step 3: Deploying 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
Let's start by reviewing the starter contract in the `src/` directory.
introduces a crowdfunding campaign contract aimed at supporting Zeek's inventive ventures.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
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).

contract CrowdfundingCampaign {
address public owner;
uint256 public fundingGoal;
uint256 public totalFundsRaised;
mapping(address => uint256) public contributions;
::drop-panel
::panel{label="CrowdfundingCampaign.sol"}
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

event ContributionReceived(address contributor, uint256 amount);
event GoalReached(uint256 totalFundsRaised);
contract CrowdfundingCampaign {
address public owner;
uint256 public fundingGoal;
uint256 public totalFundsRaised;
mapping(address => uint256) public contributions;

constructor(uint256 _fundingGoal) {
owner = msg.sender;
fundingGoal = _fundingGoal;
}
event ContributionReceived(address contributor, uint256 amount);
event GoalReached(uint256 totalFundsRaised);

constructor(uint256 _fundingGoal) {
owner = msg.sender;
fundingGoal = _fundingGoal;
}

function contribute() public payable {
require(msg.value > 0, "Contribution must be greater than 0");
contributions[msg.sender] += msg.value;
totalFundsRaised += msg.value;
function contribute() public payable {
require(msg.value > 0, "Contribution must be greater than 0");
contributions[msg.sender] += msg.value;
totalFundsRaised += msg.value;

emit ContributionReceived(msg.sender, msg.value);
emit ContributionReceived(msg.sender, msg.value);

if (totalFundsRaised >= fundingGoal) {
emit GoalReached(totalFundsRaised);
if (totalFundsRaised >= fundingGoal) {
emit GoalReached(totalFundsRaised);
}
}
}

function withdrawFunds() public {
require(msg.sender == owner, "Only the owner can withdraw funds");
require(totalFundsRaised >= fundingGoal, "Funding goal not reached");
function withdrawFunds() public {
require(msg.sender == owner, "Only the owner can withdraw funds");
require(totalFundsRaised >= fundingGoal, "Funding goal not reached");

uint256 amount = address(this).balance;
totalFundsRaised = 0;
uint256 amount = address(this).balance;
totalFundsRaised = 0;

(bool success, ) = payable(owner).call{value: amount}("");
require(success, "Transfer failed.");
}
(bool success, ) = payable(owner).call{value: amount}("");
require(success, "Transfer failed.");
}

function getTotalFundsRaised() public view returns (uint256) {
return totalFundsRaised;
}
function getTotalFundsRaised() public view returns (uint256) {
return totalFundsRaised;
}

function getFundingGoal() public view returns (uint256) {
return fundingGoal;
function getFundingGoal() public view returns (uint256) {
return fundingGoal;
}
}
}
```
```
::
::

The `CrowdfundingCampaign` contract is designed for project crowdfunding.
Owned and deployed with a set funding goal, it features:
Expand All @@ -92,6 +97,7 @@ Owned and deployed with a set funding goal, it features:

### Compile contract

<!-- :display-partial{path = "/_partials/_compile-solidity-contracts-foundry"} -->
Smart contracts deployed to zkSync must be compiled using our custom compiler.
For this particular guide we are making use of `zksolc`.

Expand Down Expand Up @@ -121,7 +127,7 @@ located in the `/out` folder.
### Deploy

This section outlines the steps to deploy the `CrowdfundingCampaign` contract.
The deployment script is located at `/script/Deploy.s.sol`.
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
// SPDX-License-Identifier: UNLICENSED
Expand All @@ -145,8 +151,10 @@ contract DeployCrowdfundContract is Script {

**Key Components:**

- **contractArtifactName:** Identifies the `CrowdfundingCampaign` contract for deployment.
- **constructorArguments:** Sets initialization parameters for the contract.
- **Constructor Argument:** The `CrowdfundingCampaign` contract is initialized with
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

Expand Down
Loading

0 comments on commit 6f863e9

Please sign in to comment.