Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zksync 101 content #14

Closed
wants to merge 61 commits into from
Closed
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
c7bc343
feat: initial quickcode guide for deploying contract using hardhat or…
dutterbutter Apr 2, 2024
fd75318
feat: initial quickcode guide for deploying contract using hardhat or…
dutterbutter Apr 2, 2024
cf516c3
chore: update navigation
dutterbutter Apr 2, 2024
f2b794a
fix: update nav link
dutterbutter Apr 2, 2024
eaa957e
feat: create components for markdown content
itsacoyote Apr 3, 2024
c238360
chore: Foundry content, and minor improvements
dutterbutter Apr 5, 2024
308e6ae
chore: Foundry content, and minor improvements
dutterbutter Apr 5, 2024
f471161
chore: rename dir to quick-start instead of quick-code
dutterbutter Apr 5, 2024
03aa7d8
feat: adds deploy factories and testing, still some issues to resolve…
dutterbutter Apr 7, 2024
2bda316
feat: update upgrading directories and content
dutterbutter Apr 9, 2024
583f2d7
debug: adds dev tools for improved debugging
dutterbutter Apr 9, 2024
4ebae9f
fix: fix content switch basepath issue
dutterbutter Apr 9, 2024
d99e4c6
chore: resolve conflicts
dutterbutter Apr 9, 2024
03dda78
chore: fix spelling
dutterbutter Apr 9, 2024
ccf0cfe
chore: fix nav in contributing
dutterbutter Apr 9, 2024
9cf02d5
chore: content updates
dutterbutter Apr 10, 2024
6fb91aa
chore: content updates
dutterbutter Apr 11, 2024
f00ce98
chore: content updates for upgrades
dutterbutter Apr 11, 2024
8f916d6
Merge branch 'staging' of github.com:matter-labs/zksync-docs into db/…
dutterbutter Apr 11, 2024
e7da9fd
chore: update with staging
dutterbutter Apr 11, 2024
a8ba6ea
feat: 101 content
uF4No Apr 12, 2024
2261e5b
Merge branch 'staging' of https://github.com/matter-labs/zksync-docs …
uF4No Apr 15, 2024
c97122e
fix: images quickstart
uF4No Apr 15, 2024
cdac4a7
fix: partials
uF4No Apr 15, 2024
213f006
fix: remix link url
uF4No Apr 15, 2024
82bc64a
fix: improve remix plugin design
uF4No Apr 15, 2024
be1878d
fix: remix partials wording
uF4No Apr 15, 2024
98999ae
feat: adds paymaster tutorial
uF4No Apr 19, 2024
0c0049a
Merge branch 'staging' of https://github.com/matter-labs/zksync-docs …
uF4No Apr 19, 2024
fdd5b46
fix: confict wrongly merged
uF4No Apr 19, 2024
f8a1f1d
fix: spell
uF4No Apr 19, 2024
650fa5e
fix: folder structure
uF4No Apr 19, 2024
ed46ef2
fix: markdown line lenght
uF4No Apr 19, 2024
f5ec2da
fix: markdown lint
uF4No Apr 22, 2024
df62b28
Merge branch 'staging' of https://github.com/matter-labs/zksync-docs …
uF4No Apr 22, 2024
1180a8e
chore: update with staging
dutterbutter Apr 22, 2024
dc1f44a
chore: update navigation to reflect changes
dutterbutter Apr 22, 2024
47d4920
fix: add zeeks to spelling
dutterbutter Apr 22, 2024
e580620
fix: repo links
uF4No Apr 23, 2024
e8b8f86
fix: repo links in buttons
uF4No Apr 23, 2024
7421b9f
feat: adds faucets page
uF4No Apr 23, 2024
c147133
fix: md lint
uF4No Apr 23, 2024
bbb147d
fix: broken link
uF4No Apr 23, 2024
afc90fc
fix: links in partials
uF4No Apr 23, 2024
541b7e3
feat: adds aave faucet
uF4No Apr 23, 2024
a798f00
feat: adds paymaster diagram
uF4No Apr 23, 2024
0286426
fix: image url
uF4No Apr 23, 2024
8485a22
fix: broken callout
uF4No Apr 23, 2024
e2d3e2f
fix: broken callouts
uF4No Apr 23, 2024
e7212e9
fix: md lint
uF4No Apr 23, 2024
4fe96a2
fix: network adder buttons design
uF4No Apr 24, 2024
fb14ca9
fix: comments from PR review
uF4No Apr 24, 2024
4984b1f
fix: PR comments
uF4No Apr 24, 2024
23366f7
fix: buttons md components
uF4No Apr 25, 2024
f9ad1f6
Merge branch 'staging' of https://github.com/matter-labs/zksync-docs …
uF4No Apr 25, 2024
ca81729
fix: component props declaration
uF4No Apr 25, 2024
7ee9828
feat: replaces testnet with constant
uF4No Apr 25, 2024
09ccf17
fix: image path
uF4No Apr 25, 2024
9237cbc
fix: broken link
uF4No Apr 25, 2024
e91063a
fix: broken links
uF4No Apr 25, 2024
c228908
fix: adds removed icons
uF4No Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
.idea
public
**/*.md
*.md
Binary file modified bun.lockb
Binary file not shown.
68 changes: 68 additions & 0 deletions components/content/NetworkAdder.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<script setup lang="ts">
const props = defineProps<{
network: { type: String; required: true };
uF4No marked this conversation as resolved.
Show resolved Hide resolved
}>();

const chainName = props.network === 'mainnet' ? 'zkSync Era Mainnet' : 'zkSync Sepolia Testnet';

function addNetwork() {
const config = {
mainnet: {
chainId: '0x144',
rpcUrls: ['https://mainnet.era.zksync.io'],
blockExplorerUrls: ['https://explorer.zksync.io/'],
},
testnet: {
chainId: '0x12c',
rpcUrls: ['https://sepolia.era.zksync.dev'],
blockExplorerUrls: ['https://sepolia.explorer.zksync.dev/'],
},
}[props.network];

window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [
{
chainId: config.chainId,
chainName: chainName,
nativeCurrency: { name: 'Ethereum', symbol: 'ETH', decimals: 18 },
iconUrls: ['https://docs.zksync.io/favicon-32x32.png'],
rpcUrls: config.rpcUrls,
blockExplorerUrls: config.blockExplorerUrls,
},
],
});
}
</script>

<template>
<UButton
type="button"
icon="metamask"
uF4No marked this conversation as resolved.
Show resolved Hide resolved
@click="addNetwork"
>
<img
width="32"
src="/images/metamask_logo.svg"
class="m-0 p-0"
:alt="Metamask"
/>
Add {{ chainName }}
</UButton>
</template>

<style scoped>
.add-network {
display: flex;
align-items: center;
justify-content: center;
padding: 4px 8px;
gap: 4px;
cursor: pointer;
border: 1px solid #000;
}

img[src*='/images/metamask_logo.svg'] {
content: url('/images/metamask_logo.svg');
}
</style>
uF4No marked this conversation as resolved.
Show resolved Hide resolved
75 changes: 75 additions & 0 deletions content/00.build/00.zksync-101/1.zksync-overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
title: zkSync overview
description: A quick overview of what is zkSync
---

## What is zkSync?

**zkSync Era** is a Layer 2 **[ZK
rollup](https://docs.zksync.io/build/developer-reference/rollups.html#what-are-zk-rollups)**, a trustless protocol that
uses cryptographic validity proofs to provide scalable and low-cost transactions on Ethereum. In zkSync Era, computation
is performed off-chain and most data is stored off-chain as well. Transactions are bundled into batches before
generating a validity proof. As all validity proofs are proven on the Ethereum mainchain, users enjoy the same security
level as in Ethereum.

DIAGRAM L1-L2

zkSync Era is made to look and feel like Ethereum, but with a higher throughput and lower fees. Just like on Ethereum,
smart contracts are written in Solidity/Vyper and can be called using the same clients as the other EVM-compatible
chains.

You don't need to register a separate private key before using it; zkSync supports existing Ethereum wallets out of the
box.

## Main features
:check-icon Mainnet-like security with zero reliance on 3rd parties.

:check-icon Permissionless EVM-compatible smart contracts.

:check-icon Preserving key EVM features, such as smart contract composability.

:check-icon Standard Web3 API.

:check-icon State updates via transaction outputs (also known as state diffs) which provides significant cost savings
over transaction inputs.

:check-icon Native account abstraction with improvements over EIP4337 (implemented in Ethereum and other rollups).

You can find [more information about zkSync Era in l2beat](https://l2beat.com/scaling/projects/zksync-era#stage).

## Developer experience

zkSync Era was built to provide a similar developer experience as Ethereum.

:check-icon Smart contracts can be written in Solidity or Vyper.

:check-icon Most contracts work out of the box so migrating projects is seamless.

:check-icon Smart contracts are compiled with custom compilers: **[zksolc and
zkvyper](https://docs.zksync.io/zk-stack/components/compiler/toolchain/overview.html)**.

:check-icon Use existing frameworks
like **[Hardhat](https://docs.zksync.io/build/tooling/hardhat/getting-started.html),** libraries like Ethers, Viem, or
web3.js, and tools like theGraph, Thirdweb, or Chainlink.

:check-icon Web3 API compatibility enables support of most developer tools.

:check-icon Different **[tools for testing and debugging
locally](https://docs.zksync.io/build/test-and-debug/getting-started.html)**.

## User experience

Interacting with applications built on zkSync Era is seamless, cheap and fast.

- Transactions have instant confirmations and fast finality on L1.
- Transaction fees are extremely low (see [average transaction costs
here](https://www.growthepie.xyz/fundamentals/transaction-costs)).
- Transaction fees can be conveniently paid with ERC20 tokens (e.g. USDC) thanks to **[native account abstraction and
paymasters](https://docs.zksync.io/build/developer-reference/account-abstraction.html)**.
- Support for existing Ethereum-based wallets like Metamask, TrustWallet, Zerion or Rabby.

## Get started
uF4No marked this conversation as resolved.
Show resolved Hide resolved

- Follow [this guide to Add the zkSync network to your wallet](./2.connect-zksync.md).
- Get [testnet funds from one of the faucets](./3.faucet.md)
- Deploy your first smart contract to zkSync Era in the **[quickstart](4.quickstart.md)**.
uF4No marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 43 additions & 0 deletions content/00.build/00.zksync-101/2.connect-zksync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: Connect to zkSync
description: Step-by-step guide to connect your wallet to zkSync.
---

## Add zkSync Era to your wallet

You can add zkSync Era to your wallet using the buttons below:

<network-adder network="mainnet"></network-adder>
<network-adder network="testnet"></network-adder>
uF4No marked this conversation as resolved.
Show resolved Hide resolved

### Manual settings

To manually add zkSync Era as a custom network in your wallet, follow these steps:

1. Find the “Add Network” option in your wallet (in Metamask, you can find this in the networks dropdown).
2. Click “Add Network"
3. Fill in the following details for the zkSync Era network you want to add:

#### Mainnet network details

- Network Name: `zkSync Era Mainnet`
- RPC URL: `https://mainnet.era.zksync.io`
- Chain ID: `324`
- Currency Symbol: `ETH`
- Block Explorer URL: `https://explorer.zksync.io/`
- WebSocket URL: `wss://mainnet.era.zksync.io/ws`

#### Sepolia testnet network details

- Network Name: `zkSync Era Sepolia Testnet`
- RPC URL: `https://sepolia.era.zksync.dev`
- Chain ID: `300`
- Currency Symbol: `ETH`
- Block Explorer URL: `https://sepolia.explorer.zksync.io/`
- WebSocket URL: `wss://sepolia.era.zksync.dev/ws`

Click on "Save" to add the zkSync Era network to your wallet.

## **How to get started?**

Begin by deploying your first smart contract to zkSync Era in the **[quickstart](4.quickstart.md)**.
uF4No marked this conversation as resolved.
Show resolved Hide resolved
38 changes: 38 additions & 0 deletions content/00.build/00.zksync-101/3.faucet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: Network Faucets
description: Get testnet funds to build and deploy to zkSync testnet.
---

To access the testnet funds (Sepolia) you can use one of the following third party faucets:

## zkSync testnet faucet by Chainstack

[Chainstack Faucet](https://faucet.chainstack.com/zksync-testnet-faucet) is an easy to use Multi-Chain Faucet. You can
use Chainstack Faucet to claim zkSync Sepolia Testnet **0.05 ETH every 24 hours**. Chainstack API key is required.
uF4No marked this conversation as resolved.
Show resolved Hide resolved

## LearnWeb3

You can use [LearnWeb3's zkSync Sepolia Faucet](https://learnweb3.io/faucets/zksync_sepolia/) to claim zkSync Sepolia
Testnet **0.01 ETH per day**. GitHub authentication is required.
uF4No marked this conversation as resolved.
Show resolved Hide resolved

## Sepolia faucets
uF4No marked this conversation as resolved.
Show resolved Hide resolved

Use any of the following faucets to claim SepoliaETH, which you can bridge to zkSync testnet using the [zkSync
bridge](https://portal.zksync.io/bridge/?network=sepolia).

- [LearnWeb3 Sepolia faucet](https://learnweb3.io/faucets/sepolia)
- [QuickNode Sepolia faucet](https://faucet.quicknode.com/ethereum/sepolia)
- [Alchemy Sepolia faucet](https://sepoliafaucet.com/)
- [Proof of Work Sepolia faucet](https://sepolia-faucet.pk910.de/)
- [Infura Sepolia faucet](https://www.infura.io/faucet/sepolia/)
- [Ethereum Ecosystem Sepolia faucet](https://www.ethereum-ecosystem.com/faucets/ethereum-sepolia)

## Circle USDC faucet

You can use [Circle's Testnet Faucet](https://faucet.circle.com/) to claim testnet USDC on zkSync Sepolia or Ethereum
Sepolia Testnet.

## Aave ERC20 token faucet

Aave provides a [Sepolia faucet](https://staging.aave.com/faucet/) that you can use to claim popular ERC20 tokens like
WBTC, USDT, LINK, AAVE or DAI.
uF4No marked this conversation as resolved.
Show resolved Hide resolved
130 changes: 130 additions & 0 deletions content/00.build/00.zksync-101/4.quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
title: Quickstart
uF4No marked this conversation as resolved.
Show resolved Hide resolved
description: Deploy a smart contract to zkSync in under 5 minutes
---

This tutorial shows you how to deploy and interact with a smart contract on zkSync Era in less than 5 minutes.
It will help you get familiar with the zkSync smart contract development and deployment process using different tools.

This is what we're going to do:

:check-icon Fund your wallet with zkSync Sepolia ETH.

:check-icon Build a smart contract to exchange secret messages with Zeek.

:check-icon Deploy the smart contract to the zkSync Era Sepolia testnet using Remix or Atlas.

Before you start, make sure that
[you’ve configured the zkSync Sepolia tesnet in your browser wallet by following the instructions here](./2.connect-zksync.md).

## Step 1: Fund your wallet

zkSync Testnet ETH is used to deploy and interact with smart contracts on the zkSync Sepolia testnet.
You can get it directly into zkSync Sepolia testnet using the
**[following faucet provided by LearnWeb3](https://learnweb3.io/faucets/zksync_sepolia/)**
(GitHub authentication required) or any of the other available faucets.
uF4No marked this conversation as resolved.
Show resolved Hide resolved

You can also bridge SepoliaETH to the zkSync Sepolia testnet using the
**[zkSync bridge](https://portal.zksync.io/bridge/?network=sepolia)**.
uF4No marked this conversation as resolved.
Show resolved Hide resolved

You can check the balance of your account in the
**[zkSync Sepolia explorer](https://sepolia.explorer.zksync.io/)**.

## Review the smart contract code

The smart contract will store messages from users in a hashed format and emit events with replies from Zeek.
The entire code is as follows:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract ZeekSecretMessages {
bytes32[] private messages;

// Event to acknowledge a new message
event MessageReceived(string);

constructor() {
// Zeek initializes the contract with a welcome message
emit MessageReceived("Zeek welcomes you to zkSync!");
}

// Function to send a "secret" message to Zeek
function sendMessage(string memory _message) public {
bytes32 hashedMessage = keccak256(abi.encodePacked(_message));
messages.push(hashedMessage);

// Acknowledge the message receipt with Zeek's reply
emit MessageReceived("ZK is the endgame - Message received!");
}

// Function to count the total messages sent to Zeek
function getTotalMessages() public view returns (uint) {
return messages.length;
}
}
```

The Solidity smart contract contains two functions:

- `sendMessage` stores the messages sent by users in the `messages` state variable.
- `getTotalMessages` returns the number of messages stored in the smart contract.

::callout{icon="i-heroicons-light-bulb"}
zkSync Era is EVM compatible.
You can write smart contracts with Solidity or Vyper and use existing popular libraries like OpenZeppelin.
::

## Step 2: deploy the contract

To deploy the contract we can use either Atlas or Remix:

::content-switcher
---
items: [{
label: 'Atlas',
partial: '_quickstart/_atlas_deploy_contract'
}, {
label: 'Remix',
partial: '_quickstart/_remix_deploy_contract'
}]
---
::

## Step 3: check the contract in explorer

Copy the smart contract address from Atlas/Remix and search it the zkSync Sepolia testnet explorer. You’ll see the
uF4No marked this conversation as resolved.
Show resolved Hide resolved
contract has a transaction from the message we just sent.

![Contract in zkSync explorer](/images/101-quickstart/101-contract-deployed.png)

Click on the transaction hash link to check all its details, like timestamp, the account that send it, transaction fee
etc. The status will be “Processed” on zkSync and “Sending” on Ethereum. To learn more about the transaction lifecycle
on zkSync, check out this section of the docs.
uF4No marked this conversation as resolved.
Show resolved Hide resolved

In the “Contract” tab you’ll see the contract source code as Atlas and Remix automatically verified the contract for us.
When a smart contract is verified in a block explorer, it means that the source code of the contract has been published
and matched to the compiled version on the blockchain enhancing transparency, as users can review the contract’s source
code to understand its functions and intentions.

Finally in the “Events” tab, you’ll see the replies from Zeek as these are emitted as events in our smart contract.

![Contract events in zkSync explorer](/images/101-quickstart/101-contract-events.png)

ZK is the endgame ✌️

## Takeaways

- **EVM-compatibility**: zkSync Era is EVM-compatible and you can write smart contracts in Solidity or Vyper as in
Ethereum.
- **Custom compilers**: smart contracts deployed to zkSync Era must be compiled with the customs compilers: `zksolc` for
Solidity and `zkvyper` for Vyper.
- **Browser-based IDEs**: Existing tools like Atlas and Remix use zkSync custom compilers under the hood.

## Next steps

- Join the zkSync developer community in Discord where you can ask any questions about this tutorial in the #dev-101
channel
- Continue learning by deploying an ERC20 token to zkSync Era.
- Join our GitHub Discussions community to help other devs building on zkSync or share your project.
Loading
Loading