Skip to content

Commit

Permalink
Merge pull request #136 from scaffold-eth/backmerge-10-10-24-new
Browse files Browse the repository at this point in the history
depreciate default alchemy key (scaffold-eth#955)
  • Loading branch information
technophile-04 authored Oct 10, 2024
2 parents b6f0d70 + 0562f98 commit a5587c6
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-books-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-eth": patch
---

deprecate default alchemy key (scaffold-eth#955)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Run smart contract test with `yarn hardhat:test` or `yarn foundry:test` dependin
- 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,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
Expand Down
7 changes: 5 additions & 2 deletions templates/base/packages/nextjs/services/web3/wagmiConfig.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const RPC_CHAIN_NAMES: Record<number, string> = {
};

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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 12 additions & 13 deletions templates/solidity-frameworks/foundry/packages/foundry/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ import "hardhat-deploy";
import "hardhat-deploy-ethers";
${imports.filter(Boolean).join("\n")}
// 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: {
Expand All @@ -56,48 +55,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: {
Expand Down

0 comments on commit a5587c6

Please sign in to comment.