Skip to content

Commit

Permalink
feat: yarn compile + yarn deploy working for Escrow.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
uri-99 committed Feb 16, 2024
1 parent 096cf27 commit e1e259a
Show file tree
Hide file tree
Showing 11 changed files with 3,726 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/zksync/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WALLET_PRIVATE_KEY=
113 changes: 113 additions & 0 deletions contracts/zksync/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.vscode

# hardhat artifacts
artifacts
cache

# zksync artifacts
artifacts-zk
cache-zk

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
21 changes: 21 additions & 0 deletions contracts/zksync/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Matter Labs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
51 changes: 51 additions & 0 deletions contracts/zksync/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# zkSync Hardhat project template

This project was scaffolded with [zksync-cli](https://github.com/matter-labs/zksync-cli).

## Project Layout

- `/contracts`: Contains solidity smart contracts.
- `/deploy`: Scripts for contract deployment and interaction.
- `/test`: Test files.
- `hardhat.config.ts`: Configuration settings.

## How to Use

- `npm run compile`: Compiles contracts.
- `npm run deploy`: Deploys using script `/deploy/deploy.ts`.
- `npm run interact`: Interacts with the deployed contract using `/deploy/interact.ts`.
- `npm run test`: Tests the contracts.

Note: Both `npm run deploy` and `npm run interact` are set in the `package.json`. You can also run your files directly, for example: `npx hardhat deploy-zksync --script deploy.ts`

### Environment Settings

To keep private keys safe, this project pulls in environment variables from `.env` files. Primarily, it fetches the wallet's private key.

Rename `.env.example` to `.env` and fill in your private key:

```
WALLET_PRIVATE_KEY=your_private_key_here...
```

### Network Support

`hardhat.config.ts` comes with a list of networks to deploy and test contracts. Add more by adjusting the `networks` section in the `hardhat.config.ts`. To make a network the default, set the `defaultNetwork` to its name. You can also override the default using the `--network` option, like: `hardhat test --network dockerizedNode`.

### Local Tests

Running `npm run test` by default runs the [zkSync In-memory Node](https://era.zksync.io/docs/tools/testing/era-test-node.html) provided by the [@matterlabs/hardhat-zksync-node](https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-node.html) tool.

Important: zkSync In-memory Node currently supports only the L2 node. If contracts also need L1, use another testing environment like Dockerized Node. Refer to [test documentation](https://era.zksync.io/docs/tools/testing/) for details.

## Useful Links

- [Docs](https://era.zksync.io/docs/dev/)
- [Official Site](https://zksync.io/)
- [GitHub](https://github.com/matter-labs)
- [Twitter](https://twitter.com/zksync)
- [Discord](https://join.zksync.dev/)

## License

This project is under the [MIT](./LICENSE) license.
File renamed without changes.
55 changes: 55 additions & 0 deletions contracts/zksync/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { HardhatUserConfig } from "hardhat/config";

import "@matterlabs/hardhat-zksync-node";
import "@matterlabs/hardhat-zksync-deploy";
import "@matterlabs/hardhat-zksync-solc";
import "@matterlabs/hardhat-zksync-verify";

const config: HardhatUserConfig = {
defaultNetwork: "zkSyncSepoliaTestnet",
networks: {
zkSyncSepoliaTestnet: {
url: "https://sepolia.era.zksync.dev",
ethNetwork: "sepolia",
zksync: true,
verifyURL: "https://explorer.sepolia.era.zksync.dev/contract_verification",
},
zkSyncMainnet: {
url: "https://mainnet.era.zksync.io",
ethNetwork: "mainnet",
zksync: true,
verifyURL: "https://zksync2-mainnet-explorer.zksync.io/contract_verification",
},
zkSyncGoerliTestnet: { // deprecated network
url: "https://testnet.era.zksync.dev",
ethNetwork: "goerli",
zksync: true,
verifyURL: "https://zksync2-testnet-explorer.zksync.dev/contract_verification",
},
dockerizedNode: {
url: "http://localhost:3050",
ethNetwork: "http://localhost:8545",
zksync: true,
},
inMemoryNode: {
url: "http://127.0.0.1:8011",
ethNetwork: "", // in-memory node doesn't support eth node; removing this line will cause an error
zksync: true,
},
hardhat: {
zksync: true,
},
},
zksolc: {
version: "latest",
settings: {
// find all available options in the official documentation
// https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-solc.html#configuration
},
},
solidity: {
version: "0.8.17",
},
};

export default config;
34 changes: 34 additions & 0 deletions contracts/zksync/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "zksync-hardhat-template",
"description": "A template for zkSync smart contracts development with Hardhat",
"private": true,
"author": "Matter Labs",
"license": "MIT",
"repository": "https://github.com/matter-labs/zksync-hardhat-template.git",
"scripts": {
"deploy": "hardhat deploy-zksync --script deploy.ts",
"interact": "hardhat deploy-zksync --script interact.ts",
"compile": "hardhat compile",
"clean": "hardhat clean",
"test": "hardhat test --network hardhat"
},
"devDependencies": {
"@matterlabs/hardhat-zksync-deploy": "^1.1.2",
"@matterlabs/hardhat-zksync-node": "^1.0.1",
"@matterlabs/hardhat-zksync-solc": "^1.0.6",
"@matterlabs/hardhat-zksync-verify": "^1.2.2",
"@matterlabs/zksync-contracts": "^0.6.1",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@openzeppelin/contracts": "^4.6.0",
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"chai": "^4.3.7",
"dotenv": "^16.0.3",
"ethers": "^6.9.2",
"hardhat": "^2.12.4",
"mocha": "^10.2.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.5",
"zksync-ethers": "^6.0.0"
}
}
9 changes: 9 additions & 0 deletions contracts/zksync/scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { deployContract } from "./utils";

// It will deploy a Escrow contract to selected network
// as well as verify it on Block Explorer if possible for the network
export default async function () {
const contractArtifactName = "Escrow";
const constructorArguments = [];
await deployContract(contractArtifactName, constructorArguments);
}
36 changes: 36 additions & 0 deletions contracts/zksync/scripts/interact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as hre from "hardhat";
import { getWallet } from "./utils";
import { ethers } from "ethers";

// Address of the contract to interact with
const CONTRACT_ADDRESS = "";
if (!CONTRACT_ADDRESS) throw "⛔️ Provide address of the contract to interact with!";

// An example of a script to interact with the contract
export default async function () {
console.log(`Running script to interact with contract ${CONTRACT_ADDRESS}`);

// Load compiled contract info
const contractArtifact = await hre.artifacts.readArtifact("Greeter");

// Initialize contract instance for interaction
const contract = new ethers.Contract(
CONTRACT_ADDRESS,
contractArtifact.abi,
getWallet() // Interact with the contract on behalf of this wallet
);

// Run contract read function
const response = await contract.greet();
console.log(`Current message is: ${response}`);

// Run contract write function
const transaction = await contract.setGreeting("Hello people!");
console.log(`Transaction hash of setting new message: ${transaction.hash}`);

// Wait until transaction is processed
await transaction.wait();

// Read message after transaction
console.log(`The message now is: ${await contract.greet()}`);
}
Loading

0 comments on commit e1e259a

Please sign in to comment.