diff --git a/templates/react/next-ethers5/src/components/WriteContractPrepared.tsx b/templates/react/next-ethers5/src/components/WriteContractPrepared.tsx
index cdde3af..d5fa912 100644
--- a/templates/react/next-ethers5/src/components/WriteContractPrepared.tsx
+++ b/templates/react/next-ethers5/src/components/WriteContractPrepared.tsx
@@ -1,8 +1,7 @@
-'use client'
+'use client';
-import { useState, useEffect } from 'react';
+import { useState, useCallback, useEffect } from 'react';
import { Contract } from 'zksync-ethers';
-
import { useAsync } from '../hooks/useAsync';
import { daiContractConfig } from './contracts';
import { useEthereum } from './Context';
@@ -11,17 +10,22 @@ export function WriteContractPrepared() {
const [amount, setAmount] = useState
(null);
const { getSigner, getProvider } = useEthereum();
- const getContractInstance = () => {
- return new Contract(daiContractConfig.address, daiContractConfig.abi, getSigner()!);
- }
+ const getContractInstance = useCallback(() => {
+ const signer = getSigner();
+ if (!signer) throw new Error("Signer not available");
+ return new Contract(daiContractConfig.address, daiContractConfig.abi, signer);
+ }, [getSigner]);
- const { result: preparedTransaction, execute: prepareTransaction, inProgress: prepareInProgress, error: prepareError } = useAsync(async () => {
+ const prepareTransaction = useCallback(async () => {
const contract = getContractInstance();
// random address for testing, replace with contract address that you want to allow to spend your tokens
- const spender = "0xa1cf087DB965Ab02Fb3CFaCe1f5c63935815f044"
+ const spender = "0xa1cf087DB965Ab02Fb3CFaCe1f5c63935815f044";
+
+ const provider = getProvider();
+ if (!provider) throw new Error("Provider not available");
- const gasPrice = await getProvider()!.getGasPrice();
+ const gasPrice = await provider.getGasPrice();
const gasLimit = await contract.estimateGas.approve(spender, amount);
return {
@@ -31,28 +35,40 @@ export function WriteContractPrepared() {
gasLimit
}
};
+ }, [amount, getContractInstance, getProvider]);
+
+ const { result: preparedTransaction, execute: executePrepareTransaction, inProgress: prepareInProgress, error: prepareError } = useAsync(prepareTransaction);
+
+ const { result: receipt, execute: waitForReceipt, inProgress: receiptInProgress, error: receiptError } = useAsync(async (transactionHash: string) => {
+ const provider = getProvider();
+ if (!provider) throw new Error("Provider not available");
+
+ return await provider.waitForTransaction(transactionHash);
});
- const { result: transaction, execute: sendTransaction, inProgress, error } = useAsync(async () => {
+ const sendTransaction = useCallback(async () => {
+ if (!preparedTransaction) throw new Error("Prepared transaction is not available");
+
const contract = getContractInstance();
- const result = await contract.approve(...preparedTransaction!.args, preparedTransaction!.overrides);
+ const result = await contract.approve(...preparedTransaction.args, preparedTransaction.overrides);
waitForReceipt(result.hash);
return result;
- });
+ }, [getContractInstance, preparedTransaction, waitForReceipt]);
- const { result: receipt, execute: waitForReceipt, inProgress: receiptInProgress, error: receiptError } = useAsync(async (transactionHash) => {
- return await getProvider()!.waitForTransaction(transactionHash);
- });
+ const { result: transaction, execute: executeSendTransaction, inProgress, error } = useAsync(sendTransaction);
useEffect(() => {
if (!amount) return;
- prepareTransaction();
- }, [amount]);
+ executePrepareTransaction();
+ }, [amount, executePrepareTransaction]);
- const handleSubmit = (e: React.FormEvent) => {
+ const handleSubmit = useCallback(async (e: React.FormEvent) => {
e.preventDefault();
- sendTransaction();
- };
+ const result = await executeSendTransaction();
+ if (result) {
+ waitForReceipt(result.hash);
+ }
+ }, [executeSendTransaction, waitForReceipt]);
return (
diff --git a/templates/react/next-wagmi-rainbowkit/README.md b/templates/react/next-wagmi-rainbowkit/README.md
index ad4a2f3..3713e63 100644
--- a/templates/react/next-wagmi-rainbowkit/README.md
+++ b/templates/react/next-wagmi-rainbowkit/README.md
@@ -2,6 +2,24 @@ This is a [zkSync](https://zksync.io) + [wagmi](https://wagmi.sh) + [RainbowKit]
# Getting Started
+## Requirements
+- A wallet extension like MetaMask installed in your browser.
+- A WalletConnect project ID to connect.
+- Node.js and npm installed.
+- To use the `dockerized local node` or `in memory local node` setups, you will need to run the respective services in Docker. For detailed instructions on setting up and running these nodes, refer to the [Documentation](https://docs.zksync.io/build/test-and-debug).
+
+## Setup
+
+1. Copy the `.env.example` file to `.env`:
+
+```bash
+cp .env.example .env
+```
+2. Update the .env file with your WalletConnect project ID.
+
+## Installation
+Install dependencies with `npm install`.
+
Run `npm run dev` in your terminal, and then open [localhost:3000](http://localhost:3000) in your browser.
Once the webpage has loaded, changes made to files inside the `src/` directory (e.g. `src/pages/index.tsx`) will automatically update the webpage.
diff --git a/templates/react/next-wagmi-web3modal/README.md b/templates/react/next-wagmi-web3modal/README.md
index ce68878..225bbfc 100644
--- a/templates/react/next-wagmi-web3modal/README.md
+++ b/templates/react/next-wagmi-web3modal/README.md
@@ -2,6 +2,24 @@ This is a [zkSync](https://zksync.io) + [wagmi](https://wagmi.sh) + [Web3Modal](
# Getting Started
+## Requirements
+- A wallet extension like MetaMask installed in your browser.
+- A WalletConnect project ID to connect.
+- Node.js and npm installed.
+- To use the `dockerized local node` or `in memory local node` setups, you will need to run the respective services in Docker. For detailed instructions on setting up and running these nodes, refer to the [Documentation](https://docs.zksync.io/build/test-and-debug).
+
+## Setup
+
+1. Copy the `.env.example` file to `.env`:
+
+```bash
+cp .env.example .env
+```
+2. Update the .env file with your WalletConnect project ID.
+
+## Installation
+Install dependencies with `npm install`.
+
Run `npm run dev` in your terminal, and then open [localhost:3000](http://localhost:3000) in your browser.
Once the webpage has loaded, changes made to files inside the `src/` directory (e.g. `src/pages/index.tsx`) will automatically update the webpage.
diff --git a/templates/react/next-wagmi/README.md b/templates/react/next-wagmi/README.md
index c96b709..09c2b79 100644
--- a/templates/react/next-wagmi/README.md
+++ b/templates/react/next-wagmi/README.md
@@ -2,6 +2,14 @@ This is a [zkSync](https://zksync.io) + [wagmi](https://wagmi.sh) + [Next.js](ht
# Getting Started
+## Requirements
+- A wallet extension like MetaMask installed in your browser.
+- Node.js and npm installed.
+- To use the `dockerized local node` or `in memory local node` setups, you will need to run the respective services in Docker. For detailed instructions on setting up and running these nodes, refer to the [Documentation](https://docs.zksync.io/build/test-and-debug).
+
+## Installation
+Install dependencies with `npm install`.
+
Run `npm run dev` in your terminal, and then open [localhost:3000](http://localhost:3000) in your browser.
Once the webpage has loaded, changes made to files inside the `src/` directory (e.g. `src/pages/index.tsx`) will automatically update the webpage.
diff --git a/templates/react/vite-ethers/README.md b/templates/react/vite-ethers/README.md
index aa3220c..43084dd 100644
--- a/templates/react/vite-ethers/README.md
+++ b/templates/react/vite-ethers/README.md
@@ -2,6 +2,14 @@ This is a [zkSync](https://zksync.io) + [ethers](https://docs.ethers.org/v6/) +
# Getting Started
+## Requirements
+- A wallet extension like MetaMask installed in your browser.
+- Node.js and npm installed.
+- To use the `dockerized local node` or `in memory local node` setups, you will need to run the respective services in Docker. For detailed instructions on setting up and running these nodes, refer to the [Documentation](https://docs.zksync.io/build/test-and-debug).
+
+## Installation
+Install dependencies with `npm install`.
+
Run `npm run dev` in your terminal, and then open [localhost:5173](http://localhost:5173) in your browser.
Once the webpage has loaded, changes made to files inside the `src/` directory (e.g. `src/App.tsx`) will automatically update the webpage.
diff --git a/templates/react/vite-ethers/src/components/Context.tsx b/templates/react/vite-ethers/src/components/Context.tsx
index 39ee791..7eee04d 100644
--- a/templates/react/vite-ethers/src/components/Context.tsx
+++ b/templates/react/vite-ethers/src/components/Context.tsx
@@ -20,7 +20,7 @@ const zkSync: Chain = {
const zkSyncSepoliaTestnet: Chain = {
id: 300,
name: "zkSync Sepolia Testnet",
- rpcUrl: "https://rpc.ankr.com/eth_sepolia",
+ rpcUrl: "https://sepolia.era.zksync.dev",
blockExplorerUrl: "https://sepolia.etherscan.io"
}
export const chains: Chain[] = [
@@ -169,4 +169,4 @@ export const useEthereum = () => {
throw new Error("useEthereum must be used within an EthereumProvider");
}
return context;
-}
\ No newline at end of file
+}
diff --git a/templates/react/vite-ethers5/README.md b/templates/react/vite-ethers5/README.md
index 19415c9..7a2a384 100644
--- a/templates/react/vite-ethers5/README.md
+++ b/templates/react/vite-ethers5/README.md
@@ -2,6 +2,14 @@ This is a [zkSync](https://zksync.io) + [ethers v5](https://docs.ethers.org/v5/)
# Getting Started
+## Requirements
+- A wallet extension like MetaMask installed in your browser.
+- Node.js and npm installed.
+- To use the `dockerized local node` or `in memory local node` setups, you will need to run the respective services in Docker. For detailed instructions on setting up and running these nodes, refer to the [Documentation](https://docs.zksync.io/build/test-and-debug).
+
+## Installation
+Install dependencies with `npm install`.
+
Run `npm run dev` in your terminal, and then open [localhost:5173](http://localhost:5173) in your browser.
Once the webpage has loaded, changes made to files inside the `src/` directory (e.g. `src/App.tsx`) will automatically update the webpage.
diff --git a/templates/react/vite-ethers5/src/components/Context.tsx b/templates/react/vite-ethers5/src/components/Context.tsx
index 3f7923f..5d43a99 100644
--- a/templates/react/vite-ethers5/src/components/Context.tsx
+++ b/templates/react/vite-ethers5/src/components/Context.tsx
@@ -17,7 +17,7 @@ const zkSync: Chain = {
const zkSyncSepoliaTestnet: Chain = {
id: 300,
name: "zkSync Sepolia Testnet",
- rpcUrl: "https://rpc.ankr.com/eth_sepolia",
+ rpcUrl: "https://sepolia.era.zksync.dev",
blockExplorerUrl: "https://sepolia.etherscan.io"
}
export const chains: Chain[] = [
@@ -165,4 +165,4 @@ export const useEthereum = () => {
throw new Error("useEthereum must be used within an EthereumProvider");
}
return context;
-}
\ No newline at end of file
+}
diff --git a/templates/react/vite-wagmi-web3modal/README.md b/templates/react/vite-wagmi-web3modal/README.md
index efb849a..0efb778 100644
--- a/templates/react/vite-wagmi-web3modal/README.md
+++ b/templates/react/vite-wagmi-web3modal/README.md
@@ -2,6 +2,24 @@ This is a [zkSync](https://zksync.io) + [wagmi](https://wagmi.sh) + [Web3Modal](
# Getting Started
+## Requirements
+- A wallet extension like MetaMask installed in your browser.
+- A WalletConnect project ID to connect.
+- Node.js and npm installed.
+- To use the `dockerized local node` or `in memory local node` setups, you will need to run the respective services in Docker. For detailed instructions on setting up and running these nodes, refer to the [Documentation](https://docs.zksync.io/build/test-and-debug).
+
+## Setup
+
+1. Copy the `.env.example` file to `.env`:
+
+```bash
+cp .env.example .env
+```
+2. Update the .env file with your WalletConnect project ID.
+
+## Installation
+Install dependencies with `npm install`.
+
Run `npm run dev` in your terminal, and then open [localhost:5173](http://localhost:5173) in your browser.
Once the webpage has loaded, changes made to files inside the `src/` directory (e.g. `src/App.tsx`) will automatically update the webpage.
diff --git a/templates/react/vite-wagmi/README.md b/templates/react/vite-wagmi/README.md
index 78fe565..148adc3 100644
--- a/templates/react/vite-wagmi/README.md
+++ b/templates/react/vite-wagmi/README.md
@@ -2,6 +2,14 @@ This is a [zkSync](https://zksync.io) + [wagmi](https://wagmi.sh) + [Vite](https
# Getting Started
+## Requirements
+- A wallet extension like MetaMask installed in your browser.
+- Node.js and npm installed.
+- To use the `dockerized local node` or `in memory local node` setups, you will need to run the respective services in Docker. For detailed instructions on setting up and running these nodes, refer to the [Documentation](https://docs.zksync.io/build/test-and-debug).
+
+## Installation
+Install dependencies with `npm install`.
+
Run `npm run dev` in your terminal, and then open [localhost:5173](http://localhost:5173) in your browser.
Once the webpage has loaded, changes made to files inside the `src/` directory (e.g. `src/App.tsx`) will automatically update the webpage.