├── contracts └── Greeter.sol ├── hardhat.config.ts ├── deploy └── deploy.ts └── README.md /contracts/Greeter.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: Unlicense 2 | pragma solidity ^0.8.0; 3 | 4 | contract Greeter { 5 | string private greeting; 6 | 7 | constructor(string memory _greeting) { 8 | greeting = _greeting; 9 | } 10 | 11 | function greet() public view returns (string memory) { 12 | return greeting; 13 | } 14 | 15 | function setGreeting(string memory _greeting) public { 16 | greeting = _greeting; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /hardhat.config.ts: -------------------------------------------------------------------------------- 1 | import "@matterlabs/hardhat-zksync-deploy"; 2 | import "@matterlabs/hardhat-zksync-solc"; 3 | 4 | module.exports = { 5 | zksolc: { 6 | version: "1.3.1", 7 | compilerSource: "binary", 8 | settings: {}, 9 | }, 10 | defaultNetwork: "zkSyncTestnet", 11 | 12 | networks: { 13 | zkSyncTestnet: { 14 | url: "https://zksync2-testnet.zksync.dev", 15 | ethNetwork: "goerli", // Can also be the RPC URL of the network (e.g. `https://goerli.infura.io/v3/`) 16 | zksync: true, 17 | }, 18 | }, 19 | solidity: { 20 | version: "0.8.17", 21 | }, 22 | }; 23 | -------------------------------------------------------------------------------- /deploy/deploy.ts: -------------------------------------------------------------------------------- 1 | import { Wallet, utils } from "zksync-web3"; 2 | import * as ethers from "ethers"; 3 | import { HardhatRuntimeEnvironment } from "hardhat/types"; 4 | import { Deployer } from "@matterlabs/hardhat-zksync-deploy"; 5 | 6 | // An example of a deploy script that will deploy and call a simple contract. 7 | export default async function (hre: HardhatRuntimeEnvironment) { 8 | console.log(`Running deploy script for the Greeter contract`); 9 | 10 | // Initialize the wallet. 11 | const wallet = new Wallet("Здесь впишите свой приватный ключ от мм, ковычки оставить"); 12 | 13 | // Create deployer object and load the artifact of the contract you want to deploy. 14 | const deployer = new Deployer(hre, wallet); 15 | const artifact = await deployer.loadArtifact("Greeter"); 16 | 17 | // Estimate contract deployment fee 18 | const greeting = "Hi there!"; 19 | const deploymentFee = await deployer.estimateDeployFee(artifact, [greeting]); 20 | 21 | // OPTIONAL: Deposit funds to L2 22 | // Comment this block if you already have funds on zkSync. 23 | const depositHandle = await deployer.zkWallet.deposit({ 24 | to: deployer.zkWallet.address, 25 | token: utils.ETH_ADDRESS, 26 | amount: deploymentFee.mul(2), 27 | }); 28 | // Wait until the deposit is processed on zkSync 29 | await depositHandle.wait(); 30 | 31 | // Deploy this contract. The returned object will be of a `Contract` type, similarly to ones in `ethers`. 32 | // `greeting` is an argument for contract constructor. 33 | const parsedFee = ethers.utils.formatEther(deploymentFee.toString()); 34 | console.log(`The deployment is estimated to cost ${parsedFee} ETH`); 35 | 36 | const greeterContract = await deployer.deploy(artifact, [greeting]); 37 | 38 | //obtain the Constructor Arguments 39 | console.log("constructor args:" + greeterContract.interface.encodeDeploy([greeting])); 40 | 41 | // Show the contract info. 42 | const contractAddress = greeterContract.address; 43 | console.log(`${artifact.contractName} was deployed to ${contractAddress}`); 44 | } 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Специально для канала Крипторелакс https://www.youtube.com/@Crypto-Relax 2 | # Наш телеграм : https://t.me/CRYPTORELAKS 3 | * Официальные гайды от ZkSync era : https://era.zksync.io/docs/dev/building-on-zksync/hello-world.html и https://era.zksync.io/docs/api/hardhat/getting-started.html#learn-more 4 | * Кран Goerli: https://goerlifaucet.com/ ; 5 | * Натсройка тестовой сети ZkSync: https://era.zksync.io/docs/dev/troubleshooting/important-links.html ; 6 | * Бридж для перевода в тестовую сеть zksync era : https://portal.zksync.io/bridge ; 7 | * Эксплорер для проверки контракта и транзакций : https://goerli.explorer.zksync.io/ ; 8 | 9 | # Действия : 10 | 1) Скачаиваем ( если нет ) Visual Studio Code : https://code.visualstudio.com/ 11 | 2) Добваляем в VSC нужные расширения ( Solidity, npm Intellisense ), если по ходу работы в VSC выдает ошибки и всплывает окно в нижнем правом углу с предложением скачать пакеты - соглашаемся ( у всех может быть по-разному ), чего будет не хватать из пакетов ( yarn, node.js и тд ) устанавливаем вручную ( гайдов полно в интернете ) 12 | 3) Добавляем ссылку с этого репозитория в VSC : https://github.com/sevRipen/Greeter 13 | 4) Подготавливаем метамаск : добавляем сеть ZkSync Era Testnet через https://chainlist.org/?testnets=true&search=zksync+era+testnet или вручную 14 | 5) Запрашиваем тестовые Goerli на https://goerlifaucet.com/ 15 | 6) Отправляем Goerli ETH на ZkSync Era Testnet через мост https://portal.zksync.io/bridge (внизу справа проверяем чтобы стояла ZkSync Era Goerli 16 | 7) Переходим обратно в VSC и в терминале пишем команду : ```yarn init -y``` или ```npm init -y``` 17 | 8) Затем вводим : ```sudo npm i -D typescript ts-node ethers@^5.7.2 zksync-web3@^0.13.1 hardhat @matterlabs/hardhat-zksync-solc @matterlabs/hardhat-zksync-deploy``` 18 | 9) Далее : ```yarn hardhat compile``` или ```npx hardhat compile``` 19 | 10) В ```deploy.ts``` вставляем свой приватный ключ от метамаска 20 | 11) И последняя команда : ```yarn hardhat deploy-zksync``` или ```npx hardhat deploy-zksync``` и ждем окончания деплоя контракта 21 | 12) Верефицируем контракт (см. видео ) 22 | 13) Взаимодействуем со смартконтрактом (см. видео ) 23 | --------------------------------------------------------------------------------