diff --git a/scaffolds/nextjs-dedicated-wallet/template/src/components/magic/cards/SendTransactionCard.tsx b/scaffolds/nextjs-dedicated-wallet/template/src/components/magic/cards/SendTransactionCard.tsx index f2d3a1c..e4155c6 100644 --- a/scaffolds/nextjs-dedicated-wallet/template/src/components/magic/cards/SendTransactionCard.tsx +++ b/scaffolds/nextjs-dedicated-wallet/template/src/components/magic/cards/SendTransactionCard.tsx @@ -6,7 +6,7 @@ import FormInput from '@/components/ui/FormInput'; import ErrorText from '@/components/ui/ErrorText'; import Card from '@/components/ui/Card'; import CardHeader from '@/components/ui/CardHeader'; -import { getFaucetUrl, getNetworkToken } from '@/utils/network'; +import { getFaucetUrl, getNetworkToken, isEip1559Supported } from '@/utils/network'; import showToast from '@/utils/showToast'; import Spacer from '@/components/ui/Spacer'; import TransactionHistory from '@/components/ui/TransactionHistory'; @@ -29,7 +29,7 @@ const SendTransaction = () => { setToAddressError(false); }, [amount, toAddress]); - const sendTransaction = useCallback(() => { + const sendTransaction = useCallback(async () => { if (!web3?.utils.isAddress(toAddress)) { return setToAddressError(true); } @@ -41,7 +41,8 @@ const SendTransaction = () => { from: publicAddress, to: toAddress, value: web3.utils.toWei(amount, 'ether'), - gas: 21000, + // Specify `gasPrice` if network doesn't support EIP-1559 + ...(!isEip1559Supported() && { gasPrice: await web3.eth.getGasPrice() }), }; web3.eth .sendTransaction(txnParams as any) diff --git a/scaffolds/nextjs-dedicated-wallet/template/src/utils/network.ts b/scaffolds/nextjs-dedicated-wallet/template/src/utils/network.ts index 326b2ac..fe95287 100644 --- a/scaffolds/nextjs-dedicated-wallet/template/src/utils/network.ts +++ b/scaffolds/nextjs-dedicated-wallet/template/src/utils/network.ts @@ -113,3 +113,17 @@ export const getBlockExplorer = (address: string) => { return `https://sepolia.explorer.zksync.io/address/${address}`; } }; + +export const isEip1559Supported = () => { + switch (process.env.NEXT_PUBLIC_BLOCKCHAIN_NETWORK) { + case Network.POLYGON: + case Network.POLYGON_AMOY: + case Network.ETHEREUM_SEPOLIA: + case Network.ETHEREUM: + case Network.ZKSYNC: + case Network.ZKSYNC_SEPOLIA: + return true; + case Network.ETHERLINK_TESTNET: + return false; + } +}; diff --git a/scaffolds/nextjs-universal-wallet/template/src/components/magic/cards/SendTransactionsCard.tsx b/scaffolds/nextjs-universal-wallet/template/src/components/magic/cards/SendTransactionsCard.tsx index 7ccc23a..bf23288 100644 --- a/scaffolds/nextjs-universal-wallet/template/src/components/magic/cards/SendTransactionsCard.tsx +++ b/scaffolds/nextjs-universal-wallet/template/src/components/magic/cards/SendTransactionsCard.tsx @@ -10,7 +10,7 @@ import CardHeader from '../../ui/CardHeader'; import TransactionHistory from '../../ui/TransactionHistory'; import ErrorText from '../../ui/Error'; import { useMagicContext } from '@/components/magic/MagicProvider'; -import { getFaucetUrl, getNetworkToken } from '@/utils/networks'; +import { getFaucetUrl, getNetworkToken, isEip1559Supported } from '@/utils/networks'; const SendTransaction = () => { const { web3 } = useMagicContext(); @@ -30,7 +30,7 @@ const SendTransaction = () => { setToAddressError(false); }, [amount, toAddress]); - const sendTransaction = useCallback(() => { + const sendTransaction = useCallback(async () => { if (!web3?.utils.isAddress(toAddress)) { return setToAddressError(true); } @@ -42,7 +42,8 @@ const SendTransaction = () => { from: publicAddress, to: toAddress, value: web3.utils.toWei(amount, 'ether'), - gas: 21000, + // Specify `gasPrice` if network doesn't support EIP-1559 + ...(!isEip1559Supported() && { gasPrice: await web3.eth.getGasPrice() }), }; web3.eth .sendTransaction(txnParams as any) diff --git a/scaffolds/nextjs-universal-wallet/template/src/utils/networks.ts b/scaffolds/nextjs-universal-wallet/template/src/utils/networks.ts index e35d1b0..1d812a8 100644 --- a/scaffolds/nextjs-universal-wallet/template/src/utils/networks.ts +++ b/scaffolds/nextjs-universal-wallet/template/src/utils/networks.ts @@ -113,3 +113,17 @@ export const getBlockExplorer = (address: string) => { return `https://sepolia.explorer.zksync.io/address/${address}`; } }; + +export const isEip1559Supported = () => { + switch (process.env.NEXT_PUBLIC_BLOCKCHAIN_NETWORK) { + case Network.POLYGON: + case Network.POLYGON_AMOY: + case Network.ETHEREUM_SEPOLIA: + case Network.ETHEREUM: + case Network.ZKSYNC: + case Network.ZKSYNC_SEPOLIA: + return true; + case Network.ETHERLINK_TESTNET: + return false; + } +};