Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyg0 committed Aug 22, 2024
1 parent 6504599 commit 48841e4
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 10 deletions.
11 changes: 10 additions & 1 deletion templates/react/next-ethers/src/components/SendTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { useState } from 'react';
import { ethers } from 'ethers';

import { useAsync } from '../hooks/useAsync';
import { useEthereum } from './Context';

Expand All @@ -13,9 +12,19 @@ export function SendTransaction() {
const { getSigner, getProvider } = useEthereum();

const { result: transaction, execute: sendTransaction, inProgress, error } = useAsync(async () => {
if (!address || !value) return;
const gasPrice = await getProvider()!.getGasPrice();
const gasLimit = await (await getSigner())!.estimateGas({
to: address,
value: ethers.parseEther(value),
gasPrice,
});

const result = await (await getSigner())!.sendTransaction({
to: address!,
value: ethers.parseEther(value!),
gasPrice,
gasLimit,
});
waitForReceipt(result.hash);
return result;
Expand Down
5 changes: 2 additions & 3 deletions templates/react/next-ethers/src/components/Token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { useState } from 'react';
import { Contract } from 'zksync-ethers';

import { useAsync } from '../hooks/useAsync';
import { erc20ABI, daiContractConfig } from './contracts'
import { useEthereum } from './Context';
Expand All @@ -22,8 +21,8 @@ export function Token() {
return {
symbol,
name,
decimals,
supply,
decimals: decimals.toString(),
supply: supply.toString(),
};
};

Expand Down
4 changes: 3 additions & 1 deletion templates/react/next-ethers/src/components/WriteContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ export function WriteContract() {

// random address for testing, replace with contract address that you want to allow to spend your tokens
const spender = "0xa1cf087DB965Ab02Fb3CFaCe1f5c63935815f044"
const gasPrice = await getProvider()!.getGasPrice();
const gasLimit = await contract.getFunction("approve").estimateGas(spender, amount);

const tx = await contract.approve(spender, amount);
const tx = await contract.approve(spender, amount, {gasPrice, gasLimit});

waitForReceipt(tx.hash);
return tx;
Expand Down
2 changes: 1 addition & 1 deletion templates/react/next-wagmi-rainbowkit/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1 @@
WALLET_CONNECT_PROJECT_ID=
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=
10 changes: 10 additions & 0 deletions templates/react/vite-ethers/src/components/SendTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ export function SendTransaction() {
const { getSigner, getProvider } = useEthereum();

const { result: transaction, execute: sendTransaction, inProgress, error } = useAsync(async () => {
if (!address || !value) return;
const gasPrice = await getProvider()!.getGasPrice();
const gasLimit = await (await getSigner())!.estimateGas({
to: address,
value: ethers.parseEther(value),
gasPrice,
});

const result = await (await getSigner())!.sendTransaction({
to: address!,
value: ethers.parseEther(value!),
gasPrice,
gasLimit,
});
waitForReceipt(result.hash);
return result;
Expand Down
4 changes: 2 additions & 2 deletions templates/react/vite-ethers/src/components/Token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export function Token() {
return {
symbol,
name,
decimals,
supply,
decimals: decimals.toString(),
supply: supply.toString(),
};
};

Expand Down
5 changes: 4 additions & 1 deletion templates/react/vite-ethers/src/components/WriteContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ export function WriteContract() {

// random address for testing, replace with contract address that you want to allow to spend your tokens
const spender = "0xa1cf087DB965Ab02Fb3CFaCe1f5c63935815f044"

const gasPrice = await getProvider()!.getGasPrice();
const gasLimit = await contract.getFunction("approve").estimateGas(spender, amount);

const tx = await contract.approve(spender, amount);
const tx = await contract.approve(spender, amount, {gasLimit, gasPrice});

waitForReceipt(tx.hash);
return tx;
Expand Down
2 changes: 1 addition & 1 deletion templates/react/vite-wagmi-web3modal/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=
VITE_WALLET_CONNECT_PROJECT_ID=

0 comments on commit 48841e4

Please sign in to comment.