From 4c172d5f1973a8739a2c19be5e33cfaa0ca82843 Mon Sep 17 00:00:00 2001 From: Hunter Cote Date: Thu, 4 Apr 2024 11:36:08 -0400 Subject: [PATCH 1/2] add etherlink --- core/utils/templateMappings.ts | 3 ++- .../template/src/utils/network.ts | 13 ++++++++++++ .../template/src/utils/networks.ts | 20 ++++++++++++++++--- scaffolds/prompts.ts | 3 ++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/core/utils/templateMappings.ts b/core/utils/templateMappings.ts index 702d76a..a339886 100644 --- a/core/utils/templateMappings.ts +++ b/core/utils/templateMappings.ts @@ -198,7 +198,8 @@ export const buildTemplate = async (appConfig: ConfigType): Promise config.network === 'ethereum' || config.network === 'ethereum-sepolia' || config.network === 'polygon' || - config.network === 'polygon-amoy' + config.network === 'polygon-amoy' || + config.network === 'etherlink-testnet' ) { config.chain = 'evm'; } else if (config.network === 'solana-devnet' || config.network === 'solana-mainnet') { diff --git a/scaffolds/nextjs-dedicated-wallet/template/src/utils/network.ts b/scaffolds/nextjs-dedicated-wallet/template/src/utils/network.ts index 217ee45..6fdb273 100644 --- a/scaffolds/nextjs-dedicated-wallet/template/src/utils/network.ts +++ b/scaffolds/nextjs-dedicated-wallet/template/src/utils/network.ts @@ -3,6 +3,7 @@ export enum Network { POLYGON = 'polygon', ETHEREUM_SEPOLIA = 'ethereum-sepolia', ETHEREUM = 'ethereum', + ETHERLINK_TESTNET = 'etherlink-testnet', } export const getNetworkUrl = () => { @@ -15,6 +16,8 @@ export const getNetworkUrl = () => { return 'https://eth-sepolia.g.alchemy.com/v2/fYFybLQFR9Zr2GCRcgALmAktStFKr0i0'; case Network.ETHEREUM: return 'https://eth-mainnet.g.alchemy.com/v2/fYFybLQFR9Zr2GCRcgALmAktStFKr0i0'; + case Network.ETHERLINK_TESTNET: + return 'https://node.ghostnet.etherlink.com'; default: throw new Error('Network not supported'); } @@ -30,6 +33,8 @@ export const getChainId = () => { return 11155111; case Network.ETHEREUM: return 1; + case Network.ETHERLINK_TESTNET: + return 128123; } }; @@ -41,6 +46,8 @@ export const getNetworkToken = () => { case Network.ETHEREUM: case Network.ETHEREUM_SEPOLIA: return 'ETH'; + case Network.ETHERLINK_TESTNET: + return 'XTZ'; } }; @@ -50,6 +57,8 @@ export const getFaucetUrl = () => { return 'https://faucet.polygon.technology/'; case Network.ETHEREUM_SEPOLIA: return 'https://sepoliafaucet.com/'; + case Network.ETHERLINK_TESTNET: + return 'https://faucet.etherlink.com/'; } }; @@ -63,6 +72,8 @@ export const getNetworkName = () => { return 'Ethereum (Sepolia)'; case Network.ETHEREUM: return 'Ethereum (Mainnet)'; + case Network.ETHERLINK_TESTNET: + return 'Etherlink (Testnet)'; } }; @@ -76,5 +87,7 @@ export const getBlockExplorer = (address: string) => { return `https://etherscan.io/address/${address}`; case Network.ETHEREUM_SEPOLIA: return `https://sepolia.etherscan.io/address/${address}`; + case Network.ETHERLINK_TESTNET: + return `https://testnet-explorer.etherlink.com//address/${address}`; } }; diff --git a/scaffolds/nextjs-universal-wallet/template/src/utils/networks.ts b/scaffolds/nextjs-universal-wallet/template/src/utils/networks.ts index 7de9f72..fce8060 100644 --- a/scaffolds/nextjs-universal-wallet/template/src/utils/networks.ts +++ b/scaffolds/nextjs-universal-wallet/template/src/utils/networks.ts @@ -3,6 +3,7 @@ export enum Network { POLYGON = 'polygon', ETHEREUM_SEPOLIA = 'ethereum-sepolia', ETHEREUM = 'ethereum', + ETHERLINK_TESTNET = 'etherlink-testnet', } export const getNetworkUrl = () => { @@ -15,6 +16,9 @@ export const getNetworkUrl = () => { return 'https://eth-sepolia.g.alchemy.com/v2/3jKhhva6zBqwp_dnwPlF4d0rFZhu2pjD'; case Network.ETHEREUM: return 'https://eth-mainnet.g.alchemy.com/v2/3jKhhva6zBqwp_dnwPlF4d0rFZhu2pjD'; + case Network.ETHERLINK_TESTNET: + return 'https://node.ghostnet.etherlink.com'; + default: throw new Error('Network not supported'); } @@ -25,11 +29,13 @@ export const getChainId = () => { case Network.POLYGON: return 137; case Network.POLYGON_AMOY: - return 80001; + return 80002; case Network.ETHEREUM_SEPOLIA: - return 1155111; + return 11155111; case Network.ETHEREUM: return 1; + case Network.ETHERLINK_TESTNET: + return 128123; } }; @@ -41,6 +47,8 @@ export const getNetworkToken = () => { case Network.ETHEREUM: case Network.ETHEREUM_SEPOLIA: return 'ETH'; + case Network.ETHERLINK_TESTNET: + return 'XTZ'; } }; @@ -50,6 +58,8 @@ export const getFaucetUrl = () => { return 'https://faucet.polygon.technology/'; case Network.ETHEREUM_SEPOLIA: return 'https://sepoliafaucet.com/'; + case Network.ETHERLINK_TESTNET: + return 'https://faucet.etherlink.com/'; } }; @@ -58,11 +68,13 @@ export const getNetworkName = () => { case Network.POLYGON: return 'Polygon (Mainnet)'; case Network.POLYGON_AMOY: - return 'Polygon (Mumbai)'; + return 'Polygon (Amoy)'; case Network.ETHEREUM_SEPOLIA: return 'Ethereum (Sepolia)'; case Network.ETHEREUM: return 'Ethereum (Mainnet)'; + case Network.ETHERLINK_TESTNET: + return 'Etherlink (Testnet)'; } }; @@ -76,5 +88,7 @@ export const getBlockExplorer = (address: string) => { return `https://etherscan.io/address/${address}`; case Network.ETHEREUM_SEPOLIA: return `https://sepolia.etherscan.io/address/${address}`; + case Network.ETHERLINK_TESTNET: + return `https://testnet-explorer.etherlink.com//address/${address}`; } }; diff --git a/scaffolds/prompts.ts b/scaffolds/prompts.ts index 9569bd6..e2bb928 100644 --- a/scaffolds/prompts.ts +++ b/scaffolds/prompts.ts @@ -137,7 +137,7 @@ export namespace BlockchainNetworkPrompt { name: 'chain', message: 'Which blockchain do you want to use?', choices: [ - { name: 'evm', message: 'EVM (Ethereum, Polygon, etc.)' }, + { name: 'evm', message: 'EVM (Ethereum, Etherlink, Polygon, etc.)' }, { name: 'solana', message: 'Solana' }, { name: 'flow', message: 'Flow' }, ], @@ -173,6 +173,7 @@ export namespace BlockchainNetworkPrompt { choices: [ { name: 'ethereum', message: 'Ethereum (Mainnet)' }, { name: 'ethereum-sepolia', message: 'Ethereum (Sepolia Testnet)' }, + { name: 'etherlink-testnet', message: 'Etherlink (Testnet)' }, { name: 'polygon', message: 'Polygon (Mainnet)' }, { name: 'polygon-amoy', message: 'Polygon (Amoy Testnet)' }, ], From bc9b79f726a890b5351efee60ac73e9b4f135853 Mon Sep 17 00:00:00 2001 From: Hunter Cote Date: Fri, 12 Apr 2024 12:06:25 -0400 Subject: [PATCH 2/2] handle non-eip1159 networks --- .../components/magic/cards/SendTransactionCard.tsx | 7 ++++--- .../template/src/utils/network.ts | 14 ++++++++++++++ .../magic/cards/SendTransactionsCard.tsx | 7 ++++--- .../template/src/utils/networks.ts | 14 ++++++++++++++ 4 files changed, 36 insertions(+), 6 deletions(-) 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; + } +};