Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

add etherlink #133

Merged
merged 3 commits into from
Apr 12, 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
3 changes: 2 additions & 1 deletion core/utils/templateMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ export const buildTemplate = async (appConfig: ConfigType): Promise<ConfigType>
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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
}
Expand All @@ -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)
Expand Down
29 changes: 28 additions & 1 deletion scaffolds/nextjs-dedicated-wallet/template/src/utils/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export enum Network {
POLYGON = 'polygon',
ETHEREUM_SEPOLIA = 'ethereum-sepolia',
ETHEREUM = 'ethereum',
ETHERLINK_TESTNET = 'etherlink-testnet',
ZKSYNC = 'zksync',
ZKSYNC_SEPOLIA = 'zksync-sepolia',
}
Expand All @@ -17,6 +18,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';
case Network.ZKSYNC:
return 'https://mainnet.era.zksync.io';
case Network.ZKSYNC_SEPOLIA:
Expand All @@ -40,6 +43,8 @@ export const getChainId = () => {
return 300;
case Network.ETHEREUM:
return 1;
case Network.ETHERLINK_TESTNET:
return 128123;
}
};

Expand All @@ -53,6 +58,8 @@ export const getNetworkToken = () => {
case Network.ZKSYNC:
case Network.ZKSYNC_SEPOLIA:
return 'ETH';
case Network.ETHERLINK_TESTNET:
return 'XTZ';
}
};

Expand All @@ -62,8 +69,10 @@ 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/';
case Network.ZKSYNC_SEPOLIA:
return 'https://faucet.quicknode.com/ethereum/sepolia'
return 'https://faucet.quicknode.com/ethereum/sepolia';
}
};

Expand All @@ -77,6 +86,8 @@ export const getNetworkName = () => {
return 'Ethereum (Sepolia)';
case Network.ETHEREUM:
return 'Ethereum (Mainnet)';
case Network.ETHERLINK_TESTNET:
return 'Etherlink (Testnet)';
case Network.ZKSYNC:
return 'zkSync (Mainnet)';
case Network.ZKSYNC_SEPOLIA:
Expand All @@ -94,9 +105,25 @@ 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}`;
case Network.ZKSYNC:
return `https://explorer.zksync.io/address/${address}`;
case Network.ZKSYNC_SEPOLIA:
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;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand All @@ -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)
Expand Down
33 changes: 30 additions & 3 deletions scaffolds/nextjs-universal-wallet/template/src/utils/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export enum Network {
POLYGON = 'polygon',
ETHEREUM_SEPOLIA = 'ethereum-sepolia',
ETHEREUM = 'ethereum',
ETHERLINK_TESTNET = 'etherlink-testnet',
ZKSYNC = 'zksync',
ZKSYNC_SEPOLIA = 'zksync-sepolia',
}
Expand All @@ -17,6 +18,8 @@ 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';
case Network.ZKSYNC:
return 'https://mainnet.era.zksync.io';
case Network.ZKSYNC_SEPOLIA:
Expand All @@ -33,13 +36,15 @@ export const getChainId = () => {
case Network.POLYGON_AMOY:
return 80002;
case Network.ETHEREUM_SEPOLIA:
return 1155111;
return 11155111;
case Network.ZKSYNC:
return 324;
case Network.ZKSYNC_SEPOLIA:
return 300;
case Network.ETHEREUM:
return 1;
case Network.ETHERLINK_TESTNET:
return 128123;
}
};

Expand All @@ -53,6 +58,8 @@ export const getNetworkToken = () => {
case Network.ZKSYNC:
case Network.ZKSYNC_SEPOLIA:
return 'ETH';
case Network.ETHERLINK_TESTNET:
return 'XTZ';
}
};

Expand All @@ -62,8 +69,10 @@ 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/';
case Network.ZKSYNC_SEPOLIA:
return 'https://faucet.quicknode.com/ethereum/sepolia'
return 'https://faucet.quicknode.com/ethereum/sepolia';
}
};

Expand All @@ -77,6 +86,8 @@ export const getNetworkName = () => {
return 'Ethereum (Sepolia)';
case Network.ETHEREUM:
return 'Ethereum (Mainnet)';
case Network.ETHERLINK_TESTNET:
return 'Etherlink (Testnet)';
case Network.ZKSYNC:
return 'zkSync (Mainnet)';
case Network.ZKSYNC_SEPOLIA:
Expand All @@ -94,9 +105,25 @@ 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}`;
case Network.ZKSYNC:
return `https://explorer.zksync.io/address/${address}`;
case Network.ZKSYNC_SEPOLIA:
return `https://sepolia.explorer.zksync.io/address/${address}`
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;
}
};
3 changes: 2 additions & 1 deletion scaffolds/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
],
Expand Down Expand Up @@ -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)' },
{ name: 'zksync', message: 'zkSync (Mainnet)' },
Expand Down
Loading