From d8f62286aac3991973d8187f37626926ef8fd0f8 Mon Sep 17 00:00:00 2001 From: "Shiv Bhonde | shivbhonde.eth" Date: Thu, 10 Oct 2024 09:08:55 +0700 Subject: [PATCH 1/4] depreciate default alchemy key (#955) --- README.md | 1 + packages/hardhat/.env.example | 2 +- packages/hardhat/hardhat.config.ts | 27 +++++++++---------- packages/nextjs/scaffold.config.ts | 5 ++-- packages/nextjs/services/web3/wagmiConfig.tsx | 7 +++-- .../scaffold-eth/fetchPriceFromUniswap.ts | 6 +++-- .../nextjs/utils/scaffold-eth/networks.ts | 2 +- 7 files changed, 27 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 2943c7dc1..767baca82 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ Visit your app on: `http://localhost:3000`. You can interact with your smart con - Edit your frontend homepage at `packages/nextjs/app/page.tsx`. For guidance on [routing](https://nextjs.org/docs/app/building-your-application/routing/defining-routes) and configuring [pages/layouts](https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts) checkout the Next.js documentation. - Edit your deployment scripts in `packages/hardhat/deploy` - Edit your smart contract test in: `packages/hardhat/test`. To run test use `yarn hardhat:test` +- You can add your Alchemy API Key in `scaffold.config.ts` if you want more reliability in your RPC requests. ## Documentation diff --git a/packages/hardhat/.env.example b/packages/hardhat/.env.example index a9ccb0860..38117830b 100644 --- a/packages/hardhat/.env.example +++ b/packages/hardhat/.env.example @@ -6,6 +6,6 @@ # but we recommend getting your own API Keys for Production Apps. # To access the values stored in this .env file you can use: process.env.VARIABLENAME -ALCHEMY_API_KEY= +FORKING_URL= DEPLOYER_PRIVATE_KEY= ETHERSCAN_API_KEY= diff --git a/packages/hardhat/hardhat.config.ts b/packages/hardhat/hardhat.config.ts index 7b74685f1..e82e01be4 100644 --- a/packages/hardhat/hardhat.config.ts +++ b/packages/hardhat/hardhat.config.ts @@ -10,14 +10,13 @@ import "@nomicfoundation/hardhat-verify"; import "hardhat-deploy"; import "hardhat-deploy-ethers"; -// If not set, it uses ours Alchemy's default API key. -// You can get your own at https://dashboard.alchemyapi.io -const providerApiKey = process.env.ALCHEMY_API_KEY || "oKxs-03sij-U_N0iOlrSsZFr29-IqbuF"; // If not set, it uses the hardhat account 0 private key. const deployerPrivateKey = process.env.DEPLOYER_PRIVATE_KEY ?? "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; // If not set, it uses ours Etherscan default API key. const etherscanApiKey = process.env.ETHERSCAN_API_KEY || "DNXJA8RX2Q3VZ4URQIWP7Z68CJXQZSC6AW"; +// forking rpc url +const forkingURL = process.env.FORKING_URL || ""; const config: HardhatUserConfig = { solidity: { @@ -46,48 +45,48 @@ const config: HardhatUserConfig = { // If the network you are looking for is not here you can add new network settings hardhat: { forking: { - url: `https://eth-mainnet.alchemyapi.io/v2/${providerApiKey}`, + url: forkingURL, enabled: process.env.MAINNET_FORKING_ENABLED === "true", }, }, mainnet: { - url: `https://eth-mainnet.alchemyapi.io/v2/${providerApiKey}`, + url: `https://cloudflare-eth.com`, accounts: [deployerPrivateKey], }, sepolia: { - url: `https://eth-sepolia.g.alchemy.com/v2/${providerApiKey}`, + url: `https://rpc2.sepolia.org`, accounts: [deployerPrivateKey], }, arbitrum: { - url: `https://arb-mainnet.g.alchemy.com/v2/${providerApiKey}`, + url: `https://arb1.arbitrum.io/rpc`, accounts: [deployerPrivateKey], }, arbitrumSepolia: { - url: `https://arb-sepolia.g.alchemy.com/v2/${providerApiKey}`, + url: `https://sepolia-rollup.arbitrum.io/rpc`, accounts: [deployerPrivateKey], }, optimism: { - url: `https://opt-mainnet.g.alchemy.com/v2/${providerApiKey}`, + url: `https://mainnet.optimism.io`, accounts: [deployerPrivateKey], }, optimismSepolia: { - url: `https://opt-sepolia.g.alchemy.com/v2/${providerApiKey}`, + url: `https://sepolia.optimism.io`, accounts: [deployerPrivateKey], }, polygon: { - url: `https://polygon-mainnet.g.alchemy.com/v2/${providerApiKey}`, + url: `https://polygon-rpc.com`, accounts: [deployerPrivateKey], }, polygonMumbai: { - url: `https://polygon-mumbai.g.alchemy.com/v2/${providerApiKey}`, + url: `https://rpc.ankr.com/polygon_mumbai`, accounts: [deployerPrivateKey], }, polygonZkEvm: { - url: `https://polygonzkevm-mainnet.g.alchemy.com/v2/${providerApiKey}`, + url: `https://zkevm-rpc.com`, accounts: [deployerPrivateKey], }, polygonZkEvmTestnet: { - url: `https://polygonzkevm-testnet.g.alchemy.com/v2/${providerApiKey}`, + url: `https://rpc.public.zkevm-test.net`, accounts: [deployerPrivateKey], }, gnosis: { diff --git a/packages/nextjs/scaffold.config.ts b/packages/nextjs/scaffold.config.ts index 86c737a21..74ea4d247 100644 --- a/packages/nextjs/scaffold.config.ts +++ b/packages/nextjs/scaffold.config.ts @@ -16,11 +16,10 @@ const scaffoldConfig = { // it has no effect if you only target the local network (default is 4000) pollingInterval: 30000, - // This is ours Alchemy's default API key. - // You can get your own at https://dashboard.alchemyapi.io + // You can get your Alchemy's default API key at https://dashboard.alchemyapi.io // It's recommended to store it in an env variable: // .env.local for local testing, and in the Vercel/system env config for live apps. - alchemyApiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY || "oKxs-03sij-U_N0iOlrSsZFr29-IqbuF", + alchemyApiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY || "", // This is ours WalletConnect's default project ID. // You can get your own at https://cloud.walletconnect.com diff --git a/packages/nextjs/services/web3/wagmiConfig.tsx b/packages/nextjs/services/web3/wagmiConfig.tsx index e20784321..f3eed0940 100644 --- a/packages/nextjs/services/web3/wagmiConfig.tsx +++ b/packages/nextjs/services/web3/wagmiConfig.tsx @@ -1,5 +1,5 @@ import { wagmiConnectors } from "./wagmiConnectors"; -import { Chain, createClient, http } from "viem"; +import { Chain, createClient, fallback, http } from "viem"; import { hardhat, mainnet } from "viem/chains"; import { createConfig } from "wagmi"; import scaffoldConfig from "~~/scaffold.config"; @@ -17,9 +17,12 @@ export const wagmiConfig = createConfig({ connectors: wagmiConnectors, ssr: true, client({ chain }) { + const alchemyHttpUrl = getAlchemyHttpUrl(chain.id); + const rpcFallbacks = alchemyHttpUrl ? [http(alchemyHttpUrl), http()] : [http()]; + return createClient({ chain, - transport: http(getAlchemyHttpUrl(chain.id)), + transport: fallback(rpcFallbacks), ...(chain.id !== (hardhat as Chain).id ? { pollingInterval: scaffoldConfig.pollingInterval, diff --git a/packages/nextjs/utils/scaffold-eth/fetchPriceFromUniswap.ts b/packages/nextjs/utils/scaffold-eth/fetchPriceFromUniswap.ts index 2a5ab560c..39d1553de 100644 --- a/packages/nextjs/utils/scaffold-eth/fetchPriceFromUniswap.ts +++ b/packages/nextjs/utils/scaffold-eth/fetchPriceFromUniswap.ts @@ -1,12 +1,14 @@ import { ChainWithAttributes, getAlchemyHttpUrl } from "./networks"; import { CurrencyAmount, Token } from "@uniswap/sdk-core"; import { Pair, Route } from "@uniswap/v2-sdk"; -import { Address, createPublicClient, http, parseAbi } from "viem"; +import { Address, createPublicClient, fallback, http, parseAbi } from "viem"; import { mainnet } from "viem/chains"; +const alchemyHttpUrl = getAlchemyHttpUrl(mainnet.id); +const rpcFallbacks = alchemyHttpUrl ? [http(alchemyHttpUrl), http()] : [http()]; const publicClient = createPublicClient({ chain: mainnet, - transport: http(getAlchemyHttpUrl(mainnet.id)), + transport: fallback(rpcFallbacks), }); const ABI = parseAbi([ diff --git a/packages/nextjs/utils/scaffold-eth/networks.ts b/packages/nextjs/utils/scaffold-eth/networks.ts index 6b8276fbd..39b41913c 100644 --- a/packages/nextjs/utils/scaffold-eth/networks.ts +++ b/packages/nextjs/utils/scaffold-eth/networks.ts @@ -34,7 +34,7 @@ export const RPC_CHAIN_NAMES: Record = { }; export const getAlchemyHttpUrl = (chainId: number) => { - return RPC_CHAIN_NAMES[chainId] + return scaffoldConfig.alchemyApiKey && RPC_CHAIN_NAMES[chainId] ? `https://${RPC_CHAIN_NAMES[chainId]}.g.alchemy.com/v2/${scaffoldConfig.alchemyApiKey}` : undefined; }; From ad4c237366e90aafd1c5bcd87c0fc07fb66732dc Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Thu, 10 Oct 2024 18:07:23 +0700 Subject: [PATCH 2/4] add chagneset --- .changeset/happy-books-collect.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/happy-books-collect.md diff --git a/.changeset/happy-books-collect.md b/.changeset/happy-books-collect.md new file mode 100644 index 000000000..1b6a98b51 --- /dev/null +++ b/.changeset/happy-books-collect.md @@ -0,0 +1,5 @@ +--- +"create-eth": patch +--- + +depreciate default alchemy key (scaffold-eth#955) From 50049f95611ded3ef30dc0a1bc2a506c85c99d58 Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Thu, 10 Oct 2024 18:15:17 +0700 Subject: [PATCH 3/4] update foundry example --- .../foundry/packages/foundry/.env.example | 3 --- .../foundry/packages/foundry/foundry.toml | 25 +++++++++---------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/templates/solidity-frameworks/foundry/packages/foundry/.env.example b/templates/solidity-frameworks/foundry/packages/foundry/.env.example index 952d0d8c7..bf10f5c48 100644 --- a/templates/solidity-frameworks/foundry/packages/foundry/.env.example +++ b/templates/solidity-frameworks/foundry/packages/foundry/.env.example @@ -12,9 +12,6 @@ # be auto filled when run `yarn generate`. # Although `.env` is ignored by git, it's still important that you don't paste your # actual account private key and use the generated one. -# Alchemy rpc URL is used while deploying the contracts to some testnets/mainnets, checkout `foundry.toml` for it's use. -ALCHEMY_API_KEY=oKxs-03sij-U_N0iOlrSsZFr29-IqbuF - # Etherscan API key is used to verify the contract on etherscan. ETHERSCAN_API_KEY=DNXJA8RX2Q3VZ4URQIWP7Z68CJXQZSC6AW # Default account for localhost / use "scaffold-eth-custom" if you wish to use a generated account or imported account diff --git a/templates/solidity-frameworks/foundry/packages/foundry/foundry.toml b/templates/solidity-frameworks/foundry/packages/foundry/foundry.toml index feee8aa32..e21cbf8cc 100644 --- a/templates/solidity-frameworks/foundry/packages/foundry/foundry.toml +++ b/templates/solidity-frameworks/foundry/packages/foundry/foundry.toml @@ -8,25 +8,24 @@ fs_permissions = [{ access = "read-write", path = "./"}] default_network = "http://127.0.0.1:8545" localhost = "http://127.0.0.1:8545" -mainnet = "https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_API_KEY}" -sepolia = "https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -arbitrum = "https://arb-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -arbitrumSepolia = "https://arb-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -optimism = "https://opt-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -optimismSepolia = "https://opt-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -polygon = "https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -polygonMumbai = "https://polygon-mumbai.g.alchemy.com/v2/${ALCHEMY_API_KEY}" +mainnet = "https://cloudflare-eth.com" +sepolia = "https://rpc2.sepolia.org" +arbitrum = "https://arb1.arbitrum.io/rpc" +arbitrumSepolia = "https://sepolia-rollup.arbitrum.io/rpc" +optimism = "https://mainnet.optimism.io" +optimismSepolia = "https://sepolia.optimism.io" +polygon = "https://polygon-rpc.com" +polygonMumbai = "https://rpc.ankr.com/polygon_mumbai" +polygonZkEvm = "https://zkevm-rpc.com" +polygonZkEvmTestnet = "https://rpc.public.zkevm-test.net" gnosis = "https://rpc.gnosischain.com" chiado = "https://rpc.chiadochain.net" base = "https://mainnet.base.org" -baseGoerli = "https://goerli.base.org" baseSepolia = "https://sepolia.base.org" -polygonZkEvm = "https://polygonzkevm-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -polygonZkEvmTestnet = "https://polygonzkevm-testnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" -zkSyncTestnet = "https://testnet.era.zksync.dev" -zkSync = "https://mainnet.era.zksync.io" scrollSepolia = "https://sepolia-rpc.scroll.io" scroll = "https://rpc.scroll.io" +pgn = "https://rpc.publicgoods.network" +pgnTestnet = "https://sepolia.publicgoods.network" [etherscan] polygonMumbai = { key = "${ETHERSCAN_API_KEY}" } From 0562f98365a904d8df1884544afaafdf7112b249 Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Thu, 10 Oct 2024 18:17:08 +0700 Subject: [PATCH 4/4] fix spell in changeset --- .changeset/happy-books-collect.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/happy-books-collect.md b/.changeset/happy-books-collect.md index 1b6a98b51..a3e786236 100644 --- a/.changeset/happy-books-collect.md +++ b/.changeset/happy-books-collect.md @@ -2,4 +2,4 @@ "create-eth": patch --- -depreciate default alchemy key (scaffold-eth#955) +deprecate default alchemy key (scaffold-eth#955)