diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index de422a7..4a150b6 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -7,7 +7,7 @@ assignees: '' --- -### 🐛 Bug Report for zkSync Contract Templates +### 🐛 Bug Report for ZKsync Contract Templates #### 📝 Description Provide a clear and concise description of the bug. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 66f5fd3..8f2333b 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,8 +1,8 @@ blank_issues_enabled: true contact_links: - name: zksync-developers Discussion - url: https://github.com/zkSync-Community-Hub/zkync-developers/discussions + url: https://github.com/ZKsync-Community-Hub/zkync-developers/discussions about: Please provide feedback, and ask questions here. - - name: zkSync CLI documentation page - url: https://era.zksync.io/docs/tools/zksync-cli - about: Please refer to the documentation for immediate answers. \ No newline at end of file + - name: ZKsync CLI documentation page + url: https://docs.zksync.io/build/zksync-cli + about: Please refer to the documentation for immediate answers. diff --git a/README.md b/README.md index b8bbf84..3c11a07 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,37 @@ -# zkSync Contract Templates +# ZKsync Contract Templates -Welcome to the `zkSync Contract Templates` repository. This collection is designed for developers eager to build smart contracts on zkSync, featuring templates for Hardhat with Solidity and Vyper. These templates provide a robust starting point for contract development, testing and deployment. +Welcome to the `ZKsync Contract Templates` repository. This collection is designed for developers eager to build smart contracts on ZKsync, featuring templates for Hardhat with Solidity and Vyper. These templates provide a robust starting point for contract development, testing and deployment. ## 📁 Available Templates Currently, the repository offers specific templates for Hardhat, an Ethereum development environment, tailored for both Solidity and Vyper: ### Hardhat Templates + - Ethers v6 (latest) - [Solidity Template](./templates/hardhat/solidity/) - [Vyper Template](./templates/hardhat/vyper/) -- Ethers v5 +- Ethers v5 - [Solidity Template](./templates/hardhat_ethers5/solidity/) - [Vyper Template](./templates/hardhat_ethers5/vyper/) +## 🚀 Using Templates + +To create a project using a template, first install the zksync-cli package globally by running: + +``` +npm install -g zksync-cli +``` +Once the package is installed, you can create a project using the following command and follow the prompts to select your desired template category and specific framework or tool: + +``` +zksync-cli create +``` + +When prompted, select the **Contracts** option to use the templates in this repository. + +For detailed instructions and additional resources, please refer to the [official documentation](https://docs.zksync.io/build/zksync-cli). + ## 🤝 Contribution Your contributions are always welcome! Whether it's submitting PRs, suggesting improvements, or reporting issues, your feedback is invaluable in refining these templates. @@ -27,4 +45,4 @@ Your contributions are always welcome! Whether it's submitting PRs, suggesting i ## 📜 License -This project is licensed under [MIT](./LICENSE-MIT). \ No newline at end of file +This project is licensed under [MIT](./LICENSE-MIT). diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..08cef83 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "zksync-contract-templates", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/templates/hardhat/solidity/README.md b/templates/hardhat/solidity/README.md index 862dae0..a250e18 100644 --- a/templates/hardhat/solidity/README.md +++ b/templates/hardhat/solidity/README.md @@ -1,4 +1,4 @@ -# zkSync Hardhat project template +# ZKsync Hardhat project template This project was scaffolded with [zksync-cli](https://github.com/matter-labs/zksync-cli). @@ -34,13 +34,13 @@ WALLET_PRIVATE_KEY=your_private_key_here... ### 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. +Running `npm run test` by default runs the [ZKsync In-memory Node](https://docs.zksync.io/build/test-and-debug/in-memory-node) provided by the [@matterlabs/hardhat-zksync-node](https://docs.zksync.io/build/tooling/hardhat/hardhat-zksync-node) 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. +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://docs.zksync.io/build/test-and-debug) for details. ## Useful Links -- [Docs](https://era.zksync.io/docs/dev/) +- [Docs](https://docs.zksync.io/build) - [Official Site](https://zksync.io/) - [GitHub](https://github.com/matter-labs) - [Twitter](https://twitter.com/zksync) diff --git a/templates/hardhat/solidity/deploy/utils.ts b/templates/hardhat/solidity/deploy/utils.ts index f6f4452..b5ce9a7 100644 --- a/templates/hardhat/solidity/deploy/utils.ts +++ b/templates/hardhat/solidity/deploy/utils.ts @@ -14,7 +14,7 @@ export const getProvider = () => { const rpcUrl = hre.network.config.url; if (!rpcUrl) throw `⛔️ RPC URL wasn't found in "${hre.network.name}"! Please add a "url" field to the network config in hardhat.config.ts`; - // Initialize zkSync Provider + // Initialize ZKsync Provider const provider = new Provider(rpcUrl); return provider; @@ -28,7 +28,7 @@ export const getWallet = (privateKey?: string) => { const provider = getProvider(); - // Initialize zkSync Wallet + // Initialize ZKsync Wallet const wallet = new Wallet(privateKey ?? process.env.WALLET_PRIVATE_KEY!, provider); return wallet; @@ -73,29 +73,38 @@ type DeployContractOptions = { export const deployContract = async (contractArtifactName: string, constructorArguments?: any[], options?: DeployContractOptions) => { const log = (message: string) => { if (!options?.silent) console.log(message); - } + }; log(`\nStarting deployment process of "${contractArtifactName}"...`); - + const wallet = options?.wallet ?? getWallet(); const deployer = new Deployer(hre, wallet); - const artifact = await deployer.loadArtifact(contractArtifactName).catch((error) => { - if (error?.message?.includes(`Artifact for contract "${contractArtifactName}" not found.`)) { - console.error(error.message); - throw `⛔️ Please make sure you have compiled your contracts or specified the correct contract name!`; - } else { - throw error; - } - }); + const artifact = await deployer + .loadArtifact(contractArtifactName) + .catch((error) => { + if ( + error?.message?.includes( + `Artifact for contract "${contractArtifactName}" not found.` + ) + ) { + console.error(error.message); + throw `⛔️ Please make sure you have compiled your contracts or specified the correct contract name!`; + } else { + throw error; + } + }); // Estimate contract deployment fee - const deploymentFee = await deployer.estimateDeployFee(artifact, constructorArguments || []); + const deploymentFee = await deployer.estimateDeployFee( + artifact, + constructorArguments || [] + ); log(`Estimated deployment cost: ${ethers.formatEther(deploymentFee)} ETH`); // Check if the wallet has enough balance await verifyEnoughBalance(wallet, deploymentFee); - // Deploy the contract to zkSync + // Deploy the contract to ZKsync const contract = await deployer.deploy(artifact, constructorArguments); const address = await contract.getAddress(); const constructorArgs = contract.interface.encodeDeploy(constructorArguments); @@ -122,7 +131,7 @@ export const deployContract = async (contractArtifactName: string, constructorAr /** * Rich wallets can be used for testing purposes. - * Available on zkSync In-memory node and Dockerized node. + * Available on ZKsync In-memory node and Dockerized node. */ export const LOCAL_RICH_WALLETS = [ { diff --git a/templates/hardhat/solidity/hardhat.config.ts b/templates/hardhat/solidity/hardhat.config.ts index e8db4c2..2c95b96 100644 --- a/templates/hardhat/solidity/hardhat.config.ts +++ b/templates/hardhat/solidity/hardhat.config.ts @@ -41,7 +41,7 @@ const config: HardhatUserConfig = { version: "latest", settings: { // find all available options in the official documentation - // https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-solc.html#configuration + // https://docs.zksync.io/build/tooling/hardhat/hardhat-zksync-solc#configuration }, }, solidity: { diff --git a/templates/hardhat/solidity/package.json b/templates/hardhat/solidity/package.json index 0256643..c9db400 100644 --- a/templates/hardhat/solidity/package.json +++ b/templates/hardhat/solidity/package.json @@ -1,6 +1,6 @@ { "name": "zksync-hardhat-template", - "description": "A template for zkSync smart contracts development with Hardhat", + "description": "A template for ZKsync smart contracts development with Hardhat", "private": true, "author": "Matter Labs", "license": "MIT", diff --git a/templates/hardhat/vyper/README.md b/templates/hardhat/vyper/README.md index 87811a1..3917428 100644 --- a/templates/hardhat/vyper/README.md +++ b/templates/hardhat/vyper/README.md @@ -1,4 +1,4 @@ -# zkSync Hardhat Vyper template +# ZKsync Hardhat Vyper template This project was scaffolded with [zksync-cli](https://github.com/matter-labs/zksync-cli). @@ -34,13 +34,13 @@ WALLET_PRIVATE_KEY=your_private_key_here... ### 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. +Running `npm run test` by default runs the [ZKsync In-memory Node](https://docs.zksync.io/build/test-and-debug/in-memory-node) provided by the [@matterlabs/hardhat-zksync-node](https://docs.zksync.io/build/tooling/hardhat/hardhat-zksync-node) 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. +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://docs.zksync.io/build/test-and-debug) for details. ## Useful Links -- [Docs](https://era.zksync.io/docs/dev/) +- [Docs](https://docs.zksync.io/build) - [Official Site](https://zksync.io/) - [GitHub](https://github.com/matter-labs) - [Twitter](https://twitter.com/zksync) diff --git a/templates/hardhat/vyper/deploy/utils.ts b/templates/hardhat/vyper/deploy/utils.ts index 530a2e0..9e86aab 100644 --- a/templates/hardhat/vyper/deploy/utils.ts +++ b/templates/hardhat/vyper/deploy/utils.ts @@ -11,9 +11,10 @@ dotenv.config(); export const getProvider = () => { const rpcUrl = hre.network.config.url; - if (!rpcUrl) throw `⛔️ RPC URL wasn't found in "${hre.network.name}"! Please add a "url" field to the network config in hardhat.config.ts`; - - // Initialize zkSync Provider + if (!rpcUrl) + throw `⛔️ RPC URL wasn't found in "${hre.network.name}"! Please add a "url" field to the network config in hardhat.config.ts`; + + // Initialize ZKsync Provider const provider = new Provider(rpcUrl); return provider; @@ -22,13 +23,17 @@ export const getProvider = () => { export const getWallet = (privateKey?: string) => { if (!privateKey) { // Get wallet private key from .env file - if (!process.env.WALLET_PRIVATE_KEY) throw "⛔️ Wallet private key wasn't found in .env file!"; + if (!process.env.WALLET_PRIVATE_KEY) + throw "⛔️ Wallet private key wasn't found in .env file!"; } const provider = getProvider(); - - // Initialize zkSync Wallet - const wallet = new Wallet(privateKey ?? process.env.WALLET_PRIVATE_KEY!, provider); + + // Initialize ZKsync Wallet + const wallet = new Wallet( + privateKey ?? process.env.WALLET_PRIVATE_KEY!, + provider + ); return wallet; } @@ -52,29 +57,38 @@ type DeployContractOptions = { export const deployContract = async (contractArtifactName: string, constructorArguments?: any[], options?: DeployContractOptions) => { const log = (message: string) => { if (!options?.silent) console.log(message); - } + }; log(`\nStarting deployment process of "${contractArtifactName}"...`); - + const wallet = options?.wallet ?? getWallet(); const deployer = new Deployer(hre, wallet); - const artifact = await deployer.loadArtifact(contractArtifactName).catch((error) => { - if (error?.message?.includes(`Artifact for contract "${contractArtifactName}" not found.`)) { - console.error(error.message); - throw `⛔️ Please make sure you have compiled your contracts or specified the correct contract name!`; - } else { - throw error; - } - }); + const artifact = await deployer + .loadArtifact(contractArtifactName) + .catch((error) => { + if ( + error?.message?.includes( + `Artifact for contract "${contractArtifactName}" not found.` + ) + ) { + console.error(error.message); + throw `⛔️ Please make sure you have compiled your contracts or specified the correct contract name!`; + } else { + throw error; + } + }); // Estimate contract deployment fee - const deploymentFee = await deployer.estimateDeployFee(artifact, constructorArguments || []); + const deploymentFee = await deployer.estimateDeployFee( + artifact, + constructorArguments || [] + ); log(`Estimated deployment cost: ${ethers.formatEther(deploymentFee)} ETH`); // Check if the wallet has enough balance await verifyEnoughBalance(wallet, deploymentFee); - // Deploy the contract to zkSync + // Deploy the contract to ZKsync const contract = await deployer.deploy(artifact, constructorArguments); const address = await contract.getAddress(); const constructorArgs = contract.interface.encodeDeploy(constructorArguments); @@ -91,7 +105,7 @@ export const deployContract = async (contractArtifactName: string, constructorAr /** * Rich wallets can be used for testing purposes. - * Available on zkSync In-memory node and Dockerized node. + * Available on ZKsync In-memory node and Dockerized node. */ export const LOCAL_RICH_WALLETS = [ { diff --git a/templates/hardhat/vyper/hardhat.config.ts b/templates/hardhat/vyper/hardhat.config.ts index e9189f3..1932e4f 100644 --- a/templates/hardhat/vyper/hardhat.config.ts +++ b/templates/hardhat/vyper/hardhat.config.ts @@ -42,7 +42,7 @@ const config: HardhatUserConfig = { version: "latest", settings: { // find all available options in the official documentation - // https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-vyper.html#configuration + // https://docs.zksync.io/build/tooling/hardhat/hardhat-zksync-vyper#configuration }, }, // Currently, only Vyper 0.3.3 or 0.3.9 are supported. diff --git a/templates/hardhat/vyper/package.json b/templates/hardhat/vyper/package.json index d783809..125a66f 100644 --- a/templates/hardhat/vyper/package.json +++ b/templates/hardhat/vyper/package.json @@ -1,6 +1,6 @@ { "name": "zksync-hardhat-vyper-template", - "description": "A template for zkSync Vyper smart contracts development with Hardhat", + "description": "A template for ZKsync Vyper smart contracts development with Hardhat", "private": true, "author": "Matter Labs", "license": "MIT", diff --git a/templates/hardhat_ethers5/solidity/README.md b/templates/hardhat_ethers5/solidity/README.md index 862dae0..a250e18 100644 --- a/templates/hardhat_ethers5/solidity/README.md +++ b/templates/hardhat_ethers5/solidity/README.md @@ -1,4 +1,4 @@ -# zkSync Hardhat project template +# ZKsync Hardhat project template This project was scaffolded with [zksync-cli](https://github.com/matter-labs/zksync-cli). @@ -34,13 +34,13 @@ WALLET_PRIVATE_KEY=your_private_key_here... ### 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. +Running `npm run test` by default runs the [ZKsync In-memory Node](https://docs.zksync.io/build/test-and-debug/in-memory-node) provided by the [@matterlabs/hardhat-zksync-node](https://docs.zksync.io/build/tooling/hardhat/hardhat-zksync-node) 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. +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://docs.zksync.io/build/test-and-debug) for details. ## Useful Links -- [Docs](https://era.zksync.io/docs/dev/) +- [Docs](https://docs.zksync.io/build) - [Official Site](https://zksync.io/) - [GitHub](https://github.com/matter-labs) - [Twitter](https://twitter.com/zksync) diff --git a/templates/hardhat_ethers5/solidity/deploy/utils.ts b/templates/hardhat_ethers5/solidity/deploy/utils.ts index 61f9539..f0a5f12 100644 --- a/templates/hardhat_ethers5/solidity/deploy/utils.ts +++ b/templates/hardhat_ethers5/solidity/deploy/utils.ts @@ -15,7 +15,7 @@ export const getProvider = () => { const rpcUrl = hre.network.config.url; if (!rpcUrl) throw `⛔️ RPC URL wasn't found in "${hre.network.name}"! Please add a "url" field to the network config in hardhat.config.ts`; - // Initialize zkSync Provider + // Initialize ZKsync Provider const provider = new Provider(rpcUrl); return provider; @@ -29,7 +29,7 @@ export const getWallet = (privateKey?: string) => { const provider = getProvider(); - // Initialize zkSync Wallet + // Initialize ZKsync Wallet const wallet = new Wallet(privateKey ?? process.env.WALLET_PRIVATE_KEY!, provider); return wallet; @@ -74,29 +74,38 @@ type DeployContractOptions = { export const deployContract = async (contractArtifactName: string, constructorArguments?: any[], options?: DeployContractOptions) => { const log = (message: string) => { if (!options?.silent) console.log(message); - } + }; log(`\nStarting deployment process of "${contractArtifactName}"...`); - + const wallet = options?.wallet ?? getWallet(); const deployer = new Deployer(hre, wallet); - const artifact = await deployer.loadArtifact(contractArtifactName).catch((error) => { - if (error?.message?.includes(`Artifact for contract "${contractArtifactName}" not found.`)) { - console.error(error.message); - throw `⛔️ Please make sure you have compiled your contracts or specified the correct contract name!`; - } else { - throw error; - } - }); + const artifact = await deployer + .loadArtifact(contractArtifactName) + .catch((error) => { + if ( + error?.message?.includes( + `Artifact for contract "${contractArtifactName}" not found.` + ) + ) { + console.error(error.message); + throw `⛔️ Please make sure you have compiled your contracts or specified the correct contract name!`; + } else { + throw error; + } + }); // Estimate contract deployment fee - const deploymentFee = await deployer.estimateDeployFee(artifact, constructorArguments || []); + const deploymentFee = await deployer.estimateDeployFee( + artifact, + constructorArguments || [] + ); log(`Estimated deployment cost: ${formatEther(deploymentFee)} ETH`); // Check if the wallet has enough balance await verifyEnoughBalance(wallet, deploymentFee); - // Deploy the contract to zkSync + // Deploy the contract to ZKsync const contract = await deployer.deploy(artifact, constructorArguments); const constructorArgs = contract.interface.encodeDeploy(constructorArguments); @@ -123,7 +132,7 @@ export const deployContract = async (contractArtifactName: string, constructorAr /** * Rich wallets can be used for testing purposes. - * Available on zkSync In-memory node and Dockerized node. + * Available on ZKsync In-memory node and Dockerized node. */ export const LOCAL_RICH_WALLETS = [ { diff --git a/templates/hardhat_ethers5/solidity/hardhat.config.ts b/templates/hardhat_ethers5/solidity/hardhat.config.ts index b1e2af0..15108a5 100644 --- a/templates/hardhat_ethers5/solidity/hardhat.config.ts +++ b/templates/hardhat_ethers5/solidity/hardhat.config.ts @@ -41,7 +41,7 @@ const config: HardhatUserConfig = { version: "latest", settings: { // find all available options in the official documentation - // https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-solc.html#configuration + // https://docs.zksync.io/build/tooling/hardhat/hardhat-zksync-solc#configuration }, }, solidity: { diff --git a/templates/hardhat_ethers5/solidity/package.json b/templates/hardhat_ethers5/solidity/package.json index 1e118e5..d8c08ec 100644 --- a/templates/hardhat_ethers5/solidity/package.json +++ b/templates/hardhat_ethers5/solidity/package.json @@ -1,6 +1,6 @@ { "name": "zksync-hardhat-template", - "description": "A template for zkSync smart contracts development with Hardhat", + "description": "A template for ZKsync smart contracts development with Hardhat", "private": true, "author": "Matter Labs", "license": "MIT", diff --git a/templates/hardhat_ethers5/vyper/README.md b/templates/hardhat_ethers5/vyper/README.md index 87811a1..3917428 100644 --- a/templates/hardhat_ethers5/vyper/README.md +++ b/templates/hardhat_ethers5/vyper/README.md @@ -1,4 +1,4 @@ -# zkSync Hardhat Vyper template +# ZKsync Hardhat Vyper template This project was scaffolded with [zksync-cli](https://github.com/matter-labs/zksync-cli). @@ -34,13 +34,13 @@ WALLET_PRIVATE_KEY=your_private_key_here... ### 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. +Running `npm run test` by default runs the [ZKsync In-memory Node](https://docs.zksync.io/build/test-and-debug/in-memory-node) provided by the [@matterlabs/hardhat-zksync-node](https://docs.zksync.io/build/tooling/hardhat/hardhat-zksync-node) 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. +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://docs.zksync.io/build/test-and-debug) for details. ## Useful Links -- [Docs](https://era.zksync.io/docs/dev/) +- [Docs](https://docs.zksync.io/build) - [Official Site](https://zksync.io/) - [GitHub](https://github.com/matter-labs) - [Twitter](https://twitter.com/zksync) diff --git a/templates/hardhat_ethers5/vyper/deploy/utils.ts b/templates/hardhat_ethers5/vyper/deploy/utils.ts index 3785a07..2453747 100644 --- a/templates/hardhat_ethers5/vyper/deploy/utils.ts +++ b/templates/hardhat_ethers5/vyper/deploy/utils.ts @@ -14,7 +14,7 @@ export const getProvider = () => { const rpcUrl = hre.network.config.url; if (!rpcUrl) throw `⛔️ RPC URL wasn't found in "${hre.network.name}"! Please add a "url" field to the network config in hardhat.config.ts`; - // Initialize zkSync Provider + // Initialize ZKsync Provider const provider = new Provider(rpcUrl); return provider; @@ -28,7 +28,7 @@ export const getWallet = (privateKey?: string) => { const provider = getProvider(); - // Initialize zkSync Wallet + // Initialize ZKsync Wallet const wallet = new Wallet(privateKey ?? process.env.WALLET_PRIVATE_KEY!, provider); return wallet; @@ -75,7 +75,7 @@ export const deployContract = async (contractArtifactName: string, constructorAr // Check if the wallet has enough balance await verifyEnoughBalance(wallet, deploymentFee); - // Deploy the contract to zkSync + // Deploy the contract to ZKsync const contract = await deployer.deploy(artifact, constructorArguments); const constructorArgs = contract.interface.encodeDeploy(constructorArguments); @@ -92,7 +92,7 @@ export const deployContract = async (contractArtifactName: string, constructorAr /** * Rich wallets can be used for testing purposes. - * Available on zkSync In-memory node and Dockerized node. + * Available on ZKsync In-memory node and Dockerized node. */ export const LOCAL_RICH_WALLETS = [ { diff --git a/templates/hardhat_ethers5/vyper/hardhat.config.ts b/templates/hardhat_ethers5/vyper/hardhat.config.ts index 91e5a71..3a2ab2e 100644 --- a/templates/hardhat_ethers5/vyper/hardhat.config.ts +++ b/templates/hardhat_ethers5/vyper/hardhat.config.ts @@ -42,7 +42,7 @@ const config: HardhatUserConfig = { version: "latest", settings: { // find all available options in the official documentation - // https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-vyper.html#configuration + // https://docs.zksync.io/build/tooling/hardhat/hardhat-zksync-vyper#configuration }, }, // Currently, only Vyper 0.3.3 or 0.3.9 are supported. diff --git a/templates/hardhat_ethers5/vyper/package.json b/templates/hardhat_ethers5/vyper/package.json index d1ec37b..64a75a0 100644 --- a/templates/hardhat_ethers5/vyper/package.json +++ b/templates/hardhat_ethers5/vyper/package.json @@ -1,6 +1,6 @@ { "name": "zksync-hardhat-vyper-template", - "description": "A template for zkSync Vyper smart contracts development with Hardhat", + "description": "A template for ZKsync Vyper smart contracts development with Hardhat", "private": true, "author": "Matter Labs", "license": "MIT", diff --git a/templates/quickstart/foundry/testing/README.md b/templates/quickstart/foundry/testing/README.md index 7fc6704..07878e4 100644 --- a/templates/quickstart/foundry/testing/README.md +++ b/templates/quickstart/foundry/testing/README.md @@ -1,8 +1,8 @@ -# Foundry with zkSync Era v0.2-alpha +# Foundry with ZKsync Era v0.2-alpha -This repository enhances Foundry to support zkSync Era, enabling Solidity-based compilation, deployment, testing, and interaction with smart contracts on zkSync Era. +This repository enhances Foundry to support ZKsync Era, enabling Solidity-based compilation, deployment, testing, and interaction with smart contracts on ZKsync Era. -> 🔧 **Fork Notice:** This is a Foundry fork with added zkSync support. +> 🔧 **Fork Notice:** This is a Foundry fork with added ZKsync support. > > ⚠️ **Alpha Stage:** The project is in alpha, so you might encounter issues. > @@ -10,28 +10,28 @@ This repository enhances Foundry to support zkSync Era, enabling Solidity-based ## Changes Made -To use for zkSync environments, include `--zksync` when running `forge` or `vm.zkVm(true)` in tests. The modifications include: +To use for ZKsync environments, include `--zksync` when running `forge` or `vm.zkVm(true)` in tests. The modifications include: 1. **Compilation:** `solc` and `zksolc` are used for compiling. The resulting bytecodes are combined into `DualCompiledContract` and managed through `Executor` to `CheatcodeTracer`. 2. **EVM Interactions:** - - EVM calls are standard except for `address.balance` and `block.timestamp`/`block.number`, which pull data from zkSync (ZK-storage and ZK-specific context, respectively). + - EVM calls are standard except for `address.balance` and `block.timestamp`/`block.number`, which pull data from ZKsync (ZK-storage and ZK-specific context, respectively). 3. **Transaction Handling:** - - `CALL` and `CREATE` operations are captured and converted to zkSync transactions. This process includes fetching zkSync-equivalent bytecode, managing account nonces, and marking EOA appropriately to comply with zkSync requirements. + - `CALL` and `CREATE` operations are captured and converted to ZKsync transactions. This process includes fetching ZKsync-equivalent bytecode, managing account nonces, and marking EOA appropriately to comply with ZKsync requirements. 4. **Execution and State Management:** - - zkSync VM processes the transaction and returns state changes, which are applied to `journaled_state`. Results are relayed back. + - ZKsync VM processes the transaction and returns state changes, which are applied to `journaled_state`. Results are relayed back. 5. **Logging:** - - `console.log()` outputs within zkSync VM are captured and displayed in Foundry. + - `console.log()` outputs within ZKsync VM are captured and displayed in Foundry. 6. **Fuzzing** - - Adds config option `no_zksync_reserved_addresses`. Since zkSync reserves addresses below 2^16 as system addresses, a fuzz test would've required a broad `vm.assume` and many `vm.excludeSender` calls to exclude these. This is not only cumbersome but could also trigger `proptest`'s global `max_global_rejects` failure. When this option is set to `true` the `proptest` generation itself ensures that no invalid addresses are generated, and thus need not be filtered adding up to the `max_test_rejects` count. + - Adds config option `no_zksync_reserved_addresses`. Since ZKsync reserves addresses below 2^16 as system addresses, a fuzz test would've required a broad `vm.assume` and many `vm.excludeSender` calls to exclude these. This is not only cumbersome but could also trigger `proptest`'s global `max_global_rejects` failure. When this option is set to `true` the `proptest` generation itself ensures that no invalid addresses are generated, and thus need not be filtered adding up to the `max_test_rejects` count. ## 📊 Features & Limitations ### Features -`Foundry-zksync` offers a set of features designed to work with zkSync Era, providing a comprehensive toolkit for smart contract deployment and interaction: +`Foundry-zksync` offers a set of features designed to work with ZKsync Era, providing a comprehensive toolkit for smart contract deployment and interaction: -- **Smart Contract Deployment**: Easily deploy smart contracts to zkSync Era mainnet, testnet, or a local test node. -- **Contract Interaction**: Call and send transactions to deployed contracts on zkSync Era testnet or local test node. +- **Smart Contract Deployment**: Easily deploy smart contracts to ZKsync Era mainnet, testnet, or a local test node. +- **Contract Interaction**: Call and send transactions to deployed contracts on ZKsync Era testnet or local test node. - **Solidity Testing**: Write tests in Solidity, similar to DappTools, for a familiar testing environment. - **Fuzz Testing**: Benefit from fuzz testing, complete with shrinking of inputs and printing of counter-examples. - **Remote RPC Forking**: Utilize remote RPC forking mode, leveraging Rust's asynchronous infrastructure like tokio. @@ -45,7 +45,7 @@ To use for zkSync environments, include `--zksync` when running `forge` or `vm.z While `foundry-zksync` is **alpha stage**, there are some limitations to be aware of: - **Compile Time**: Some users may experience slower compile times. -- **Compiling Libraries**: Compiling non-inlinable libraries requires deployment and adding to configuration. For more information please refer to [official docs](https://era.zksync.io/docs/tools/hardhat/compiling-libraries.html). +- **Compiling Libraries**: Compiling non-inlinable libraries requires deployment and adding to configuration. For more information please refer to [official docs](https://docs.zksync.io/build/tooling/hardhat/compiling-libraries). ```toml libraries = [ @@ -53,7 +53,7 @@ While `foundry-zksync` is **alpha stage**, there are some limitations to be awar ] ``` -- **Create2 Address Derivation**: There are differences in Create2 Address derivation compared to Ethereum. [Read the details](https://era.zksync.io/docs/reference/architecture/differences-with-ethereum.html#create-create2). +- **Create2 Address Derivation**: There are differences in Create2 Address derivation compared to Ethereum. [Read the details](https://docs.zksync.io/build/developer-reference/ethereum-differences/evm-instructions#create-create2). - **Contract Verification**: Currently contract verification via the `--verify` flag do not work as expected but will be added shortly. - **Specific Foundry Features**: Currently features such as `--gas-report`, `--coverage` may not work as intended. We are actively working on providing support for these feature types. diff --git a/templates/quickstart/hardhat/factory/deploy/utils.ts b/templates/quickstart/hardhat/factory/deploy/utils.ts index f6f4452..5dba15e 100644 --- a/templates/quickstart/hardhat/factory/deploy/utils.ts +++ b/templates/quickstart/hardhat/factory/deploy/utils.ts @@ -14,7 +14,7 @@ export const getProvider = () => { const rpcUrl = hre.network.config.url; if (!rpcUrl) throw `⛔️ RPC URL wasn't found in "${hre.network.name}"! Please add a "url" field to the network config in hardhat.config.ts`; - // Initialize zkSync Provider + // Initialize ZKsync Provider const provider = new Provider(rpcUrl); return provider; @@ -28,7 +28,7 @@ export const getWallet = (privateKey?: string) => { const provider = getProvider(); - // Initialize zkSync Wallet + // Initialize ZKsync Wallet const wallet = new Wallet(privateKey ?? process.env.WALLET_PRIVATE_KEY!, provider); return wallet; @@ -95,7 +95,7 @@ export const deployContract = async (contractArtifactName: string, constructorAr // Check if the wallet has enough balance await verifyEnoughBalance(wallet, deploymentFee); - // Deploy the contract to zkSync + // Deploy the contract to ZKsync const contract = await deployer.deploy(artifact, constructorArguments); const address = await contract.getAddress(); const constructorArgs = contract.interface.encodeDeploy(constructorArguments); @@ -122,7 +122,7 @@ export const deployContract = async (contractArtifactName: string, constructorAr /** * Rich wallets can be used for testing purposes. - * Available on zkSync In-memory node and Dockerized node. + * Available on ZKsync In-memory node and Dockerized node. */ export const LOCAL_RICH_WALLETS = [ { @@ -165,4 +165,4 @@ export const LOCAL_RICH_WALLETS = [ address: "0xE90E12261CCb0F3F7976Ae611A29e84a6A85f424", privateKey: "0x3eb15da85647edd9a1159a4a13b9e7c56877c4eb33f614546d4db06a51868b1c" } -] \ No newline at end of file +] diff --git a/templates/quickstart/hardhat/factory/hardhat.config.ts b/templates/quickstart/hardhat/factory/hardhat.config.ts index e8db4c2..2c95b96 100644 --- a/templates/quickstart/hardhat/factory/hardhat.config.ts +++ b/templates/quickstart/hardhat/factory/hardhat.config.ts @@ -41,7 +41,7 @@ const config: HardhatUserConfig = { version: "latest", settings: { // find all available options in the official documentation - // https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-solc.html#configuration + // https://docs.zksync.io/build/tooling/hardhat/hardhat-zksync-solc#configuration }, }, solidity: { diff --git a/templates/quickstart/hardhat/factory/package.json b/templates/quickstart/hardhat/factory/package.json index e3de698..b52d829 100644 --- a/templates/quickstart/hardhat/factory/package.json +++ b/templates/quickstart/hardhat/factory/package.json @@ -1,6 +1,6 @@ { "name": "hello-zksync-quickstart", - "description": "A template for zkSync smart contracts development with Hardhat", + "description": "A template for ZKsync smart contracts development with Hardhat", "private": true, "author": "Matter Labs", "license": "MIT", diff --git a/templates/quickstart/hardhat/hello-zksync/deploy/utils.ts b/templates/quickstart/hardhat/hello-zksync/deploy/utils.ts index 6e5de5a..7a99eaa 100644 --- a/templates/quickstart/hardhat/hello-zksync/deploy/utils.ts +++ b/templates/quickstart/hardhat/hello-zksync/deploy/utils.ts @@ -14,7 +14,7 @@ export const getProvider = () => { const rpcUrl = hre.network.config.url; if (!rpcUrl) throw `⛔️ RPC URL wasn't found in "${hre.network.name}"! Please add a "url" field to the network config in hardhat.config.ts`; - // Initialize zkSync Provider + // Initialize ZKsync Provider const provider = new Provider(rpcUrl); return provider; @@ -28,7 +28,7 @@ export const getWallet = (privateKey?: string) => { const provider = getProvider(); - // Initialize zkSync Wallet + // Initialize ZKsync Wallet const wallet = new Wallet(privateKey ?? process.env.WALLET_PRIVATE_KEY!, provider); return wallet; @@ -95,7 +95,7 @@ export const deployContract = async (contractArtifactName: string, constructorAr // Check if the wallet has enough balance await verifyEnoughBalance(wallet, deploymentFee); - // Deploy the contract to zkSync + // Deploy the contract to ZKsync const contract = await deployer.deploy(artifact, constructorArguments); const address = await contract.getAddress(); const constructorArgs = contract.interface.encodeDeploy(constructorArguments); @@ -122,7 +122,7 @@ export const deployContract = async (contractArtifactName: string, constructorAr /** * Rich wallets can be used for testing purposes. - * Available on zkSync In-memory node and Dockerized node. + * Available on ZKsync In-memory node and Dockerized node. */ export const LOCAL_RICH_WALLETS = [ { diff --git a/templates/quickstart/hardhat/hello-zksync/hardhat.config.ts b/templates/quickstart/hardhat/hello-zksync/hardhat.config.ts index e8db4c2..2c95b96 100644 --- a/templates/quickstart/hardhat/hello-zksync/hardhat.config.ts +++ b/templates/quickstart/hardhat/hello-zksync/hardhat.config.ts @@ -41,7 +41,7 @@ const config: HardhatUserConfig = { version: "latest", settings: { // find all available options in the official documentation - // https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-solc.html#configuration + // https://docs.zksync.io/build/tooling/hardhat/hardhat-zksync-solc#configuration }, }, solidity: { diff --git a/templates/quickstart/hardhat/hello-zksync/package.json b/templates/quickstart/hardhat/hello-zksync/package.json index 208039e..fbc88e9 100644 --- a/templates/quickstart/hardhat/hello-zksync/package.json +++ b/templates/quickstart/hardhat/hello-zksync/package.json @@ -1,6 +1,6 @@ { "name": "hello-zksync-quickstart", - "description": "A template for zkSync smart contracts development with Hardhat", + "description": "A template for ZKsync smart contracts development with Hardhat", "private": true, "author": "Matter Labs", "license": "MIT", diff --git a/templates/quickstart/hardhat/paymaster/deploy/utils.ts b/templates/quickstart/hardhat/paymaster/deploy/utils.ts index 6e5de5a..7a99eaa 100644 --- a/templates/quickstart/hardhat/paymaster/deploy/utils.ts +++ b/templates/quickstart/hardhat/paymaster/deploy/utils.ts @@ -14,7 +14,7 @@ export const getProvider = () => { const rpcUrl = hre.network.config.url; if (!rpcUrl) throw `⛔️ RPC URL wasn't found in "${hre.network.name}"! Please add a "url" field to the network config in hardhat.config.ts`; - // Initialize zkSync Provider + // Initialize ZKsync Provider const provider = new Provider(rpcUrl); return provider; @@ -28,7 +28,7 @@ export const getWallet = (privateKey?: string) => { const provider = getProvider(); - // Initialize zkSync Wallet + // Initialize ZKsync Wallet const wallet = new Wallet(privateKey ?? process.env.WALLET_PRIVATE_KEY!, provider); return wallet; @@ -95,7 +95,7 @@ export const deployContract = async (contractArtifactName: string, constructorAr // Check if the wallet has enough balance await verifyEnoughBalance(wallet, deploymentFee); - // Deploy the contract to zkSync + // Deploy the contract to ZKsync const contract = await deployer.deploy(artifact, constructorArguments); const address = await contract.getAddress(); const constructorArgs = contract.interface.encodeDeploy(constructorArguments); @@ -122,7 +122,7 @@ export const deployContract = async (contractArtifactName: string, constructorAr /** * Rich wallets can be used for testing purposes. - * Available on zkSync In-memory node and Dockerized node. + * Available on ZKsync In-memory node and Dockerized node. */ export const LOCAL_RICH_WALLETS = [ { diff --git a/templates/quickstart/hardhat/paymaster/hardhat.config.ts b/templates/quickstart/hardhat/paymaster/hardhat.config.ts index e8db4c2..2c95b96 100644 --- a/templates/quickstart/hardhat/paymaster/hardhat.config.ts +++ b/templates/quickstart/hardhat/paymaster/hardhat.config.ts @@ -41,7 +41,7 @@ const config: HardhatUserConfig = { version: "latest", settings: { // find all available options in the official documentation - // https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-solc.html#configuration + // https://docs.zksync.io/build/tooling/hardhat/hardhat-zksync-solc#configuration }, }, solidity: { diff --git a/templates/quickstart/hardhat/paymaster/package.json b/templates/quickstart/hardhat/paymaster/package.json index 4001280..3490405 100644 --- a/templates/quickstart/hardhat/paymaster/package.json +++ b/templates/quickstart/hardhat/paymaster/package.json @@ -1,6 +1,6 @@ { "name": "hello-zksync-quickstart", - "description": "A template for zkSync smart contracts development with Hardhat", + "description": "A template for ZKsync smart contracts development with Hardhat", "private": true, "author": "Matter Labs", "license": "MIT", diff --git a/templates/quickstart/hardhat/testing/deploy/utils.ts b/templates/quickstart/hardhat/testing/deploy/utils.ts index 6e5de5a..7a99eaa 100644 --- a/templates/quickstart/hardhat/testing/deploy/utils.ts +++ b/templates/quickstart/hardhat/testing/deploy/utils.ts @@ -14,7 +14,7 @@ export const getProvider = () => { const rpcUrl = hre.network.config.url; if (!rpcUrl) throw `⛔️ RPC URL wasn't found in "${hre.network.name}"! Please add a "url" field to the network config in hardhat.config.ts`; - // Initialize zkSync Provider + // Initialize ZKsync Provider const provider = new Provider(rpcUrl); return provider; @@ -28,7 +28,7 @@ export const getWallet = (privateKey?: string) => { const provider = getProvider(); - // Initialize zkSync Wallet + // Initialize ZKsync Wallet const wallet = new Wallet(privateKey ?? process.env.WALLET_PRIVATE_KEY!, provider); return wallet; @@ -95,7 +95,7 @@ export const deployContract = async (contractArtifactName: string, constructorAr // Check if the wallet has enough balance await verifyEnoughBalance(wallet, deploymentFee); - // Deploy the contract to zkSync + // Deploy the contract to ZKsync const contract = await deployer.deploy(artifact, constructorArguments); const address = await contract.getAddress(); const constructorArgs = contract.interface.encodeDeploy(constructorArguments); @@ -122,7 +122,7 @@ export const deployContract = async (contractArtifactName: string, constructorAr /** * Rich wallets can be used for testing purposes. - * Available on zkSync In-memory node and Dockerized node. + * Available on ZKsync In-memory node and Dockerized node. */ export const LOCAL_RICH_WALLETS = [ { diff --git a/templates/quickstart/hardhat/testing/hardhat.config.ts b/templates/quickstart/hardhat/testing/hardhat.config.ts index e8db4c2..2c95b96 100644 --- a/templates/quickstart/hardhat/testing/hardhat.config.ts +++ b/templates/quickstart/hardhat/testing/hardhat.config.ts @@ -41,7 +41,7 @@ const config: HardhatUserConfig = { version: "latest", settings: { // find all available options in the official documentation - // https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-solc.html#configuration + // https://docs.zksync.io/build/tooling/hardhat/hardhat-zksync-solc#configuration }, }, solidity: { diff --git a/templates/quickstart/hardhat/testing/package.json b/templates/quickstart/hardhat/testing/package.json index 208039e..fbc88e9 100644 --- a/templates/quickstart/hardhat/testing/package.json +++ b/templates/quickstart/hardhat/testing/package.json @@ -1,6 +1,6 @@ { "name": "hello-zksync-quickstart", - "description": "A template for zkSync smart contracts development with Hardhat", + "description": "A template for ZKsync smart contracts development with Hardhat", "private": true, "author": "Matter Labs", "license": "MIT", diff --git a/templates/quickstart/hardhat/upgradability/deploy/utils.ts b/templates/quickstart/hardhat/upgradability/deploy/utils.ts index 6e5de5a..d310de1 100644 --- a/templates/quickstart/hardhat/upgradability/deploy/utils.ts +++ b/templates/quickstart/hardhat/upgradability/deploy/utils.ts @@ -12,9 +12,10 @@ dotenv.config(); export const getProvider = () => { const rpcUrl = hre.network.config.url; - if (!rpcUrl) throw `⛔️ RPC URL wasn't found in "${hre.network.name}"! Please add a "url" field to the network config in hardhat.config.ts`; - - // Initialize zkSync Provider + if (!rpcUrl) + throw `⛔️ RPC URL wasn't found in "${hre.network.name}"! Please add a "url" field to the network config in hardhat.config.ts`; + + // Initialize ZKsync Provider const provider = new Provider(rpcUrl); return provider; @@ -28,7 +29,7 @@ export const getWallet = (privateKey?: string) => { const provider = getProvider(); - // Initialize zkSync Wallet + // Initialize ZKsync Wallet const wallet = new Wallet(privateKey ?? process.env.WALLET_PRIVATE_KEY!, provider); return wallet; @@ -95,7 +96,7 @@ export const deployContract = async (contractArtifactName: string, constructorAr // Check if the wallet has enough balance await verifyEnoughBalance(wallet, deploymentFee); - // Deploy the contract to zkSync + // Deploy the contract to ZKsync const contract = await deployer.deploy(artifact, constructorArguments); const address = await contract.getAddress(); const constructorArgs = contract.interface.encodeDeploy(constructorArguments); @@ -122,7 +123,7 @@ export const deployContract = async (contractArtifactName: string, constructorAr /** * Rich wallets can be used for testing purposes. - * Available on zkSync In-memory node and Dockerized node. + * Available on ZKsync In-memory node and Dockerized node. */ export const LOCAL_RICH_WALLETS = [ { diff --git a/templates/quickstart/hardhat/upgradability/hardhat.config.ts b/templates/quickstart/hardhat/upgradability/hardhat.config.ts index e8db4c2..2c95b96 100644 --- a/templates/quickstart/hardhat/upgradability/hardhat.config.ts +++ b/templates/quickstart/hardhat/upgradability/hardhat.config.ts @@ -41,7 +41,7 @@ const config: HardhatUserConfig = { version: "latest", settings: { // find all available options in the official documentation - // https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-solc.html#configuration + // https://docs.zksync.io/build/tooling/hardhat/hardhat-zksync-solc#configuration }, }, solidity: { diff --git a/templates/quickstart/hardhat/upgradability/package.json b/templates/quickstart/hardhat/upgradability/package.json index 7e0385d..eab712f 100644 --- a/templates/quickstart/hardhat/upgradability/package.json +++ b/templates/quickstart/hardhat/upgradability/package.json @@ -1,6 +1,6 @@ { "name": "hello-zksync-quickstart", - "description": "A template for zkSync smart contracts development with Hardhat", + "description": "A template for ZKsync smart contracts development with Hardhat", "private": true, "author": "Matter Labs", "license": "MIT",