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

Chore: update readme and links #18

Merged
merged 8 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -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.
- name: ZKsync CLI documentation page
url: https://docs.zksync.io/build/zksync-cli
about: Please refer to the documentation for immediate answers.
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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).
This project is licensed under [MIT](./LICENSE-MIT).
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions templates/hardhat/solidity/README.md
Original file line number Diff line number Diff line change
@@ -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).

Expand Down Expand Up @@ -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)
Expand Down
39 changes: 24 additions & 15 deletions templates/hardhat/solidity/deploy/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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 = [
{
Expand Down
2 changes: 1 addition & 1 deletion templates/hardhat/solidity/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion templates/hardhat/solidity/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 4 additions & 4 deletions templates/hardhat/vyper/README.md
Original file line number Diff line number Diff line change
@@ -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).

Expand Down Expand Up @@ -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)
Expand Down
54 changes: 34 additions & 20 deletions templates/hardhat/vyper/deploy/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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 = [
{
Expand Down
2 changes: 1 addition & 1 deletion templates/hardhat/vyper/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion templates/hardhat/vyper/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 4 additions & 4 deletions templates/hardhat_ethers5/solidity/README.md
Original file line number Diff line number Diff line change
@@ -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).

Expand Down Expand Up @@ -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)
Expand Down
Loading
Loading