# Hello ZKsync!

***

Welcome to Validium 101 for deploying smart contracts on Validium! 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 how to:

Craft a smart contract to fund Zeek's latest adventure.

Deploy the contract onto your local in memory node.

Interact with the contract with ZKsync CLI

Let's dive in and start your developer journey on Validium!

***

This series requires some initial setup of tools to enhance your development experience building for Validium. Make sure to go through the setup provided in the initial [Getting started](https://docs.zksync.io/build/start-coding/zksync-101) section.

### Compile the CrowdfundingCampaign.sol contract <a href="#compile-the-crowdfundingcampaignsol-contract" id="compile-the-crowdfundingcampaignsol-contract"></a>

This guide introduces a crowdfunding campaign contract aimed at supporting Zeek's creative ventures. Let's start by reviewing the starter contract `CrowdfundingCampaign.sol` in the [`contracts/1-hello-zksync/CrowdfundingCampaign.sol` directory](https://github.com/matter-labs/zksync-contract-templates/blob/main/templates/101/contracts/1-hello-zksync/CrowdfundingCampaign.sol).

The `CrowdfundingCampaign` contract is designed for a simple crowdfunding campaign. This contract features:

* A constructor to initialize the campaign's funding target.
* The `contribute` method to log funds, triggering `ContributionReceived` and `GoalReached` events.
* The `withdrawFunds` method, allowing the owner to collect accumulated funds post-goal achievement.
* The `getTotalFundsRaised` method to return the total amount of funds that's been raised.
* The `getFundingGoal` method to return the goal for the campaign to reach.

Run the compile script from your project in the terminal:

npm

```bash
npm run compile
```

Upon successful compilation, you'll receive output detailing the `zksolc` and `solc` versions used during compiling and the number of Solidity files compiled.

```bash
Compiling contracts for ZKsync Era with zksolc v1.4.1 and solc v0.8.17
Compiling 15 Solidity files
Successfully compiled 15 Solidity files
```

The compiled artifacts will be located in the `/artifacts-zk` folder.

Smart contracts deployed to ZKsync must be compiled using our custom compiler. `zksolc` is the compiler used for Solidity. This is why they're placed in the `artifacts-zk` folder!

### Deploy the contract <a href="#deploy-the-contract" id="deploy-the-contract"></a>

The deployment script is located at [`/deploy/1-hello-zksync/deploy.ts`](https://github.com/matter-labs/zksync-contract-templates/blob/main/templates/101/deploy/1-hello-zksync/deploy.ts).

**Key Components:**

* **contractArtifactName:** Identifies the `CrowdfundingCampaign` contract for deployment.
* **constructorArguments:** Sets initialization parameters for the contract. In this case, the fundraising goal, converted from ether to wei to match Solidity's `uint256` type.

1. Execute the deployment command from `package.json`.

npm

```bash
npm run deploy:hello-zksync
```

Upon successful deployment, you'll receive output detailing the deployment process, including the contract address, source, and encoded constructor arguments:

```bash
Starting deployment process of "CrowdfundingCampaign"...
Estimated deployment cost: 0.0065057128 ETH

"CrowdfundingCampaign" was successfully deployed:
 - Contract address: 0x26b368C3Ed16313eBd6660b72d8e4439a697Cb0B
 - Contract source: contracts/1-hello-zksync/CrowdfundingCampaign.sol:CrowdfundingCampaign
 - Encoded constructor arguments: 0x00000000000000000000000000000000000000000000000000470de4df820000
```

### Interact with the contract <a href="#interact-with-the-contract" id="interact-with-the-contract"></a>

Now that our contract is deployed to our local in memory node, let's interact with it! We initially set up the crowdfunding campaign with an amount of `.02 ETH` for the goal.

#### [Read from the contract using ZKsync CLI](#read-from-the-contract-using-zksync-cli) <a href="#read-from-the-contract-using-zksync-cli" id="read-from-the-contract-using-zksync-cli"></a>

We can confirm the amount by calling the `getFundingGoal` method using ZKsync CLI.

In the terminal, run the following in your project directory, replacing the contract address with your contract's address:

```bash
zksync-cli contract read \
--chain in-memory-node \
--contract <0xYOUR_CONTRACT_ADDRESS> \
--abi artifacts-zk/contracts/1-hello-zksync/CrowdfundingCampaign.sol/CrowdfundingCampaign.json
```

The CLI will prompt you with a list of available methods to select from. Navigate with the arrow keys and press **Enter** on the method `getFundingGoal()`.

```bash
Using provided ABI file
? Contract method to call (Use arrow keys)
  ──────────────── Provided contract ────────────────
❯ getFundingGoal() view returns (uint256)
  getTotalFundsRaised() view returns (uint256)
  owner() view returns (address)
  ───────────────────────────────────────────────────
  Type method manually
```

* The `--chain` option defines the network we want to use, which is our local in-memory node.
* The `--contract` is the address of the contract you just deployed.
* The `--abi` provides the ABI to decode the contract and provide the list of methods to select from. Without the ABI provided, you will have to manually type out the method name.

You will get a response with the amount that we passed in to the constructor on deploy:

```bash
? Contract method to call getFundingGoal() view returns (uint256)

✔ Method response (raw): 0x00000000000000000000000000000000000000000000000000470de4df820000
✔ Decoded method response: 20000000000000000
```

#### [Write to the contract using ZKsync CLI](#write-to-the-contract-using-zksync-cli) <a href="#write-to-the-contract-using-zksync-cli" id="write-to-the-contract-using-zksync-cli"></a>

Let's fund this crowdfunding campaign and make Zeek happy!

We will write to the contract using ZKsync CLI, which requires a private key. In this demonstration we will use the second wallet provided in the list of rich wallets.

In the terminal, run the following command with your deployed contract's address:

```bash
zksync-cli contract write \
--chain in-memory-node \
--contract <0xCONTRACT_ADDRESS> \
--abi artifacts-zk/contracts/1-hello-zksync/CrowdfundingCampaign.sol/CrowdfundingCampaign.json \
--pk 0xac1e735be8536c6534bb4f17f06f6afc73b2b5ba84ac2cfb12f7461b20c0bbe3 \
--value 0.5
```

In the prompt, press **Enter** on the `contribute() payable` method. The CLI will then output the transaction information upon success.

We can read the transaction data of the contribution with the following:

```bash
zksync-cli transaction info \
--tx <0xTRANSACTION_HASH> \
--chain in-memory-node
```

Our crowdfund has reached its funding goal! Let's withdraw the funds for the owner:

```bash
zksync-cli contract write \
--chain in-memory-node \
--contract <0xCONTRACT_ADDRESS> \
--pk 0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110
```

The CLI will prompt for the method to call, we will call `withdrawFunds()`:

```bash
? Enter method to call withdrawFunds()
```

Congratulations! You've deployed a crowdfunding contract and learned how to interact with the deployed contract using ZKsync CLI!

### Takeaways <a href="#takeaways" id="takeaways"></a>

* **EVM Compatibility:** Validium is EVM compatible and you can write smart contracts in Solidity or Vyper.
* **Custom Compilation:** Contracts deployed to Validium are compiled using `zksolc` or `zkvyper` as they generate a special bytecode for Validium's ZKEVM.
* **Development Tools:** In memory node is a quick and easy local node environment to deploy to, saving costs on deployment while developing.
* **ZKsync CLI:** A powerful command line tool to interact with contracts easily.

### Next steps <a href="#next-steps" id="next-steps"></a>

Having successfully deployed your first contract on Validium, you're well on your way to becoming a proficient Validium developer. To expand your expertise:

* **Explore Contract Factories:** Enhance your project by building a contract factory for the `CrowdfundingCampaign` contract in the [next guide](https://docs.zksync.io/build/start-coding/zksync-101/contract-factory). This will allow you to efficiently manage multiple crowdfunding campaigns, each with their own unique parameters.
* **Dive Deeper into** Validium **Features:** Investigate advanced ZKsync features such as account abstraction, and paymasters.
* **Join the Community:** Engage with the [ZKsync developer community](https://docs.zksync.io/build/resources/community-channels) through forums, Discord channels, Dev Discussions, or GitHub repositories. Share your experiences, ask questions, and collaborate on projects.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://validium.gitbook.io/docs/start-coding/validium-101/hello-zksync.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
