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

feat: add ethers v6 version #4

Merged
merged 1 commit into from
Jan 13, 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
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ Welcome to the `zkSync Contract Templates` repository. This collection is design
Currently, the repository offers specific templates for Hardhat, an Ethereum development environment, tailored for both Solidity and Vyper:

### Hardhat Templates

- [Solidity Template](./templates/hardhat/solidity/)
- [Vyper Template](./templates/hardhat/vyper/)
- Ethers v6 (latest)
- [Solidity Template](./templates/hardhat/solidity/)
- [Vyper Template](./templates/hardhat/vyper/)
- Ethers v5
- [Solidity Template](./templates/hardhat_ethers5/solidity/)
- [Vyper Template](./templates/hardhat_ethers5/vyper/)

## 🀝 Contribution

Expand Down
15 changes: 7 additions & 8 deletions templates/hardhat/solidity/deploy/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { Provider, Wallet } from "zksync-ethers";
import * as hre from "hardhat";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import dotenv from "dotenv";
import { formatEther } from "ethers/lib/utils";
import { BigNumberish } from "ethers";
import { ethers } from "ethers";

import "@matterlabs/hardhat-zksync-node/dist/type-extensions";
import "@matterlabs/hardhat-zksync-verify/dist/src/type-extensions";
Expand Down Expand Up @@ -35,10 +34,10 @@ export const getWallet = (privateKey?: string) => {
return wallet;
}

export const verifyEnoughBalance = async (wallet: Wallet, amount: BigNumberish) => {
export const verifyEnoughBalance = async (wallet: Wallet, amount: bigint) => {
// Check if the wallet has enough balance
const balance = await wallet.getBalance();
if (balance.lt(amount)) throw `⛔️ Wallet balance is too low! Required ${formatEther(amount)} ETH, but current ${wallet.address} balance is ${formatEther(balance)} ETH`;
if (balance < amount) throw `⛔️ Wallet balance is too low! Required ${ethers.formatEther(amount)} ETH, but current ${wallet.address} balance is ${ethers.formatEther(balance)} ETH`;
}

/**
Expand Down Expand Up @@ -91,27 +90,27 @@ export const deployContract = async (contractArtifactName: string, constructorAr

// Estimate contract deployment fee
const deploymentFee = await deployer.estimateDeployFee(artifact, constructorArguments || []);
log(`Estimated deployment cost: ${formatEther(deploymentFee)} ETH`);
log(`Estimated deployment cost: ${ethers.formatEther(deploymentFee)} ETH`);

// Check if the wallet has enough balance
await verifyEnoughBalance(wallet, deploymentFee);

// Deploy the contract to zkSync
const contract = await deployer.deploy(artifact, constructorArguments);

const address = await contract.getAddress();
const constructorArgs = contract.interface.encodeDeploy(constructorArguments);
const fullContractSource = `${artifact.sourceName}:${artifact.contractName}`;

// Display contract deployment info
log(`\n"${artifact.contractName}" was successfully deployed:`);
log(` - Contract address: ${contract.address}`);
log(` - Contract address: ${address}`);
log(` - Contract source: ${fullContractSource}`);
log(` - Encoded constructor arguments: ${constructorArgs}\n`);

if (!options?.noVerify && hre.network.config.verifyURL) {
log(`Requesting contract verification...`);
await verifyContract({
address: contract.address,
address,
contract: fullContractSource,
constructorArguments: constructorArgs,
bytecode: artifact.bytecode,
Expand Down
Loading