From 9c4d3a6e853cc4968a555bd6dac61370b7da8963 Mon Sep 17 00:00:00 2001 From: "Shiv Bhonde | shivbhonde.eth" Date: Wed, 11 Dec 2024 10:00:51 +0530 Subject: [PATCH 1/6] reverse rpc fallback order (#1010) Co-authored-by: Rinat --- packages/nextjs/package.json | 4 +- packages/nextjs/scaffold.config.ts | 4 +- packages/nextjs/services/web3/wagmiConfig.tsx | 10 +- yarn.lock | 366 +++++++++--------- 4 files changed, 194 insertions(+), 190 deletions(-) diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index dfa82444b..8bb2576e2 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -31,8 +31,8 @@ "react-dom": "^18.3.1", "react-hot-toast": "^2.4.0", "usehooks-ts": "^3.1.0", - "viem": "2.21.32", - "wagmi": "2.12.23", + "viem": "2.21.54", + "wagmi": "2.13.4", "zustand": "^5.0.0" }, "devDependencies": { diff --git a/packages/nextjs/scaffold.config.ts b/packages/nextjs/scaffold.config.ts index 86c737a21..356076851 100644 --- a/packages/nextjs/scaffold.config.ts +++ b/packages/nextjs/scaffold.config.ts @@ -8,6 +8,8 @@ export type ScaffoldConfig = { onlyLocalBurnerWallet: boolean; }; +export const DEFAULT_ALCHEMY_API_KEY = "oKxs-03sij-U_N0iOlrSsZFr29-IqbuF"; + const scaffoldConfig = { // The networks on which your DApp is live targetNetworks: [chains.hardhat], @@ -20,7 +22,7 @@ const scaffoldConfig = { // You can get your own 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 || DEFAULT_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 30fc4f9da..37253daf4 100644 --- a/packages/nextjs/services/web3/wagmiConfig.tsx +++ b/packages/nextjs/services/web3/wagmiConfig.tsx @@ -2,7 +2,7 @@ import { wagmiConnectors } from "./wagmiConnectors"; import { Chain, createClient, fallback, http } from "viem"; import { hardhat, mainnet } from "viem/chains"; import { createConfig } from "wagmi"; -import scaffoldConfig from "~~/scaffold.config"; +import scaffoldConfig, { DEFAULT_ALCHEMY_API_KEY } from "~~/scaffold.config"; import { getAlchemyHttpUrl } from "~~/utils/scaffold-eth"; const { targetNetworks } = scaffoldConfig; @@ -17,8 +17,14 @@ export const wagmiConfig = createConfig({ connectors: wagmiConnectors, ssr: true, client({ chain }) { + let rpcFallbacks = [http()]; + const alchemyHttpUrl = getAlchemyHttpUrl(chain.id); - const rpcFallbacks = alchemyHttpUrl ? [http(), http(alchemyHttpUrl)] : [http()]; + if (alchemyHttpUrl) { + const isUsingDefaultKey = scaffoldConfig.alchemyApiKey === DEFAULT_ALCHEMY_API_KEY; + // If using default Scaffold-ETH 2 API key, we prioritize the default RPC + rpcFallbacks = isUsingDefaultKey ? [http(), http(alchemyHttpUrl)] : [http(alchemyHttpUrl), http()]; + } return createClient({ chain, diff --git a/yarn.lock b/yarn.lock index f3666b528..69eb84490 100644 --- a/yarn.lock +++ b/yarn.lock @@ -26,7 +26,7 @@ __metadata: languageName: node linkType: hard -"@adraffy/ens-normalize@npm:1.11.0": +"@adraffy/ens-normalize@npm:^1.10.1": version: 1.11.0 resolution: "@adraffy/ens-normalize@npm:1.11.0" checksum: b2911269e3e0ec6396a2e5433a99e0e1f9726befc6c167994448cd0e53dbdd0be22b4835b4f619558b568ed9aa7312426b8fa6557a13999463489daa88169ee5 @@ -200,15 +200,6 @@ __metadata: languageName: node linkType: hard -"@babel/runtime@npm:^7.19.4": - version: 7.24.5 - resolution: "@babel/runtime@npm:7.24.5" - dependencies: - regenerator-runtime: ^0.14.0 - checksum: 755383192f3ac32ba4c62bd4f1ae92aed5b82d2c6665f39eb28fa94546777cf5c63493ea92dd03f1c2e621b17e860f190c056684b7f234270fdc91e29beda063 - languageName: node - linkType: hard - "@babel/runtime@npm:^7.21.0": version: 7.23.8 resolution: "@babel/runtime@npm:7.23.8" @@ -218,12 +209,12 @@ __metadata: languageName: node linkType: hard -"@babel/runtime@npm:^7.23.2": - version: 7.24.8 - resolution: "@babel/runtime@npm:7.24.8" +"@babel/runtime@npm:^7.26.0": + version: 7.26.0 + resolution: "@babel/runtime@npm:7.26.0" dependencies: regenerator-runtime: ^0.14.0 - checksum: 6b1e4230580f67a807ad054720812bbefbb024cc2adc1159d050acbb764c4c81c7ac5f7a042c48f578987c5edc2453c71039268df059058e9501fa6023d764b0 + checksum: c8e2c0504ab271b3467a261a8f119bf2603eb857a0d71e37791f4e3fae00f681365073cc79f141ddaa90c6077c60ba56448004ad5429d07ac73532be9f7cf28a languageName: node linkType: hard @@ -288,15 +279,15 @@ __metadata: languageName: node linkType: hard -"@coinbase/wallet-sdk@npm:4.1.0": - version: 4.1.0 - resolution: "@coinbase/wallet-sdk@npm:4.1.0" +"@coinbase/wallet-sdk@npm:4.2.3": + version: 4.2.3 + resolution: "@coinbase/wallet-sdk@npm:4.2.3" dependencies: "@noble/hashes": ^1.4.0 clsx: ^1.2.1 eventemitter3: ^5.0.1 - preact: ^10.16.0 - checksum: 13ccdbf48bc43db5b9285ca4e6d13a81e1d0c7d13735b1695f9c33c4e3bb0b03683adfffc084344aed475832c3613d68e025f029fc8f2b6abe386596aeee39c9 + preact: ^10.24.2 + checksum: f1cb3c5975bf7eed46aa56077943becea16e92ac7dda46e78fb2939b3f3864815a7f218842410abb40b2b3182d09c9636ea699714c3d564009438c3611f45abc languageName: node linkType: hard @@ -316,12 +307,12 @@ __metadata: languageName: node linkType: hard -"@ecies/ciphers@npm:^0.2.0": - version: 0.2.0 - resolution: "@ecies/ciphers@npm:0.2.0" +"@ecies/ciphers@npm:^0.2.1": + version: 0.2.2 + resolution: "@ecies/ciphers@npm:0.2.2" peerDependencies: "@noble/ciphers": ^1.0.0 - checksum: 007313594d46bd94655ace5a59e6663ef8f9e9b475694ab698ec4a9b312947ba1b9c2798af7f63fac913c59d6028b0a8aa204fe613010c5c319b4a32c877e5b4 + checksum: 10a623261aa212184850fcd41788ae1f616365b5084df03ac0d7108223519e24a5f7d92caac1ee9e0f2e3b6cfae3037a42e466b25de20cf85e91098f60ba1187 languageName: node linkType: hard @@ -1177,9 +1168,9 @@ __metadata: languageName: node linkType: hard -"@metamask/sdk-communication-layer@npm:0.30.0": - version: 0.30.0 - resolution: "@metamask/sdk-communication-layer@npm:0.30.0" +"@metamask/sdk-communication-layer@npm:0.31.0": + version: 0.31.0 + resolution: "@metamask/sdk-communication-layer@npm:0.31.0" dependencies: bufferutil: ^4.0.8 date-fns: ^2.29.3 @@ -1188,68 +1179,47 @@ __metadata: uuid: ^8.3.2 peerDependencies: cross-fetch: ^4.0.0 - eciesjs: ^0.3.16 - eventemitter2: ^6.4.7 + eciesjs: "*" + eventemitter2: ^6.4.9 readable-stream: ^3.6.2 socket.io-client: ^4.5.1 - checksum: 163385834b5f0719fd4fd6c89b62426261e190df001fab39226c0eae72e6597b02f0214ebf3f3530317c974a867afe0b29c5243775dc4cde65f0c382e5f6a314 + checksum: 3f9283d828d736f331154bfa0e1368b7c7c18e00eff66ccd20e97fb86618433cef3c60ed4168e2565bda825303562eb00bb9ca101d1abdcdc3f3848f807e614e languageName: node linkType: hard -"@metamask/sdk-install-modal-web@npm:0.30.0": - version: 0.30.0 - resolution: "@metamask/sdk-install-modal-web@npm:0.30.0" +"@metamask/sdk-install-modal-web@npm:0.31.1": + version: 0.31.1 + resolution: "@metamask/sdk-install-modal-web@npm:0.31.1" dependencies: - qr-code-styling: ^1.6.0-rc.1 - peerDependencies: - i18next: 23.11.5 - react: ^18.2.0 - react-dom: ^18.2.0 - react-native: "*" - peerDependenciesMeta: - react: - optional: true - react-dom: - optional: true - react-native: - optional: true - checksum: 025c5d975b1a76cfcca50014b8860a3ecaa3a951645390b4bf7b488aedd910d35b569aab3f711dcf4c98f20e38d43d432ddcfe891f21e39ad6435b8daf9c45c6 + "@paulmillr/qr": ^0.2.1 + checksum: 9b9967ccbe4c0e07c39f0d7da18841902d726cd888b1745bc95d90d4e16aac3ccd2fb23f32edc1425874172ff8aa2f466eea30d9c0f7120fd14f2dbf7c12d6fc languageName: node linkType: hard -"@metamask/sdk@npm:0.30.1": - version: 0.30.1 - resolution: "@metamask/sdk@npm:0.30.1" +"@metamask/sdk@npm:0.31.1": + version: 0.31.1 + resolution: "@metamask/sdk@npm:0.31.1" dependencies: + "@babel/runtime": ^7.26.0 "@metamask/onboarding": ^1.0.1 "@metamask/providers": 16.1.0 - "@metamask/sdk-communication-layer": 0.30.0 - "@metamask/sdk-install-modal-web": 0.30.0 + "@metamask/sdk-communication-layer": 0.31.0 + "@metamask/sdk-install-modal-web": 0.31.1 + "@paulmillr/qr": ^0.2.1 bowser: ^2.9.0 cross-fetch: ^4.0.0 debug: ^4.3.4 - eciesjs: ^0.4.8 + eciesjs: ^0.4.11 eth-rpc-errors: ^4.0.3 - eventemitter2: ^6.4.7 - i18next: 23.11.5 - i18next-browser-languagedetector: 7.1.0 + eventemitter2: ^6.4.9 obj-multiplex: ^1.0.0 pump: ^3.0.0 - qrcode-terminal-nooctal: ^0.12.1 - react-native-webview: ^11.26.0 readable-stream: ^3.6.2 socket.io-client: ^4.5.1 + tslib: ^2.6.0 util: ^0.12.4 uuid: ^8.3.2 - peerDependencies: - react: ^18.2.0 - react-dom: ^18.2.0 - peerDependenciesMeta: - react: - optional: true - react-dom: - optional: true - checksum: c698e84b56cca3b6c39d97c12872e49eaeb9abc3950e17557838efad25e1c1102f6eec8db6ac11fae5874b430fdd6967ba7c409b3c9534eec76882d896ca2620 + checksum: f9cba369835d789e8415efca2d806b045e08bfc3f6ea5478ca3a5ec1df9a4f5180eae6e6afbd96125945e22be8d925da04b991c1b1dbdc62c21b4b5ab0658983 languageName: node linkType: hard @@ -1506,7 +1476,16 @@ __metadata: languageName: node linkType: hard -"@noble/curves@npm:1.6.0, @noble/curves@npm:^1.4.0, @noble/curves@npm:^1.6.0, @noble/curves@npm:~1.6.0": +"@noble/curves@npm:1.7.0, @noble/curves@npm:~1.7.0": + version: 1.7.0 + resolution: "@noble/curves@npm:1.7.0" + dependencies: + "@noble/hashes": 1.6.0 + checksum: e220b704f1e516f326fff985e794e840a267f5542e1388737142b08177672ebc41b460b5a5bf636d7622c68e8ae719bc042ccd8aed16dc14311450a94b5f2a05 + languageName: node + linkType: hard + +"@noble/curves@npm:^1.4.0, @noble/curves@npm:^1.6.0": version: 1.6.0 resolution: "@noble/curves@npm:1.6.0" dependencies: @@ -1550,6 +1529,20 @@ __metadata: languageName: node linkType: hard +"@noble/hashes@npm:1.6.0": + version: 1.6.0 + resolution: "@noble/hashes@npm:1.6.0" + checksum: 07729b80108d2a9b862eb4e070d4f78ca7ee86b9a9c13a4f7c338ba47a15d4386dd283235da71f21ad515fa9f0b9429fc3da39d2f2b4a50e2442212d14cfd4a9 + languageName: node + linkType: hard + +"@noble/hashes@npm:1.6.1, @noble/hashes@npm:~1.6.0": + version: 1.6.1 + resolution: "@noble/hashes@npm:1.6.1" + checksum: 57c62f65ee217c0293b4321b547792aa6d79812bfe70a7d62dc83e0f936cc677b14ed981b4e88cf8fdad37cd6d3a0cbd3bd0908b0728adc9daf066e678be8901 + languageName: node + linkType: hard + "@noble/secp256k1@npm:1.7.1, @noble/secp256k1@npm:~1.7.0": version: 1.7.1 resolution: "@noble/secp256k1@npm:1.7.1" @@ -2028,6 +2021,13 @@ __metadata: languageName: node linkType: hard +"@paulmillr/qr@npm:^0.2.1": + version: 0.2.1 + resolution: "@paulmillr/qr@npm:0.2.1" + checksum: 8a7b882f74f472759b0e5911c9c902a29c5232609373af4c5775625d9aad4ebda635d84c25be27e694144ba73d8e4204e72c3b9b59e9a375ec1d19f034a2d2ad + languageName: node + linkType: hard + "@pkgjs/parseargs@npm:^0.11.0": version: 0.11.0 resolution: "@pkgjs/parseargs@npm:0.11.0" @@ -2101,13 +2101,13 @@ __metadata: languageName: node linkType: hard -"@safe-global/safe-apps-provider@npm:0.18.3": - version: 0.18.3 - resolution: "@safe-global/safe-apps-provider@npm:0.18.3" +"@safe-global/safe-apps-provider@npm:0.18.4": + version: 0.18.4 + resolution: "@safe-global/safe-apps-provider@npm:0.18.4" dependencies: "@safe-global/safe-apps-sdk": ^9.1.0 events: ^3.3.0 - checksum: e208df42fe49474d54847d8edd44efb601b5aafaf9e25537500db7fefb1172201a62f577c749f424b34932439dd7ebe461d33b23075cf6b80fb35ef841017a30 + checksum: 8e4254c2d5d6852133d70f2fe63417796b349e2af875f45464a2d99e2423657af4465575779419d6f7c9db2155bbec42e0f617727666790fdd1c9f170b5b1794 languageName: node linkType: hard @@ -2149,13 +2149,6 @@ __metadata: languageName: node linkType: hard -"@scure/base@npm:~1.1.7": - version: 1.1.9 - resolution: "@scure/base@npm:1.1.9" - checksum: 120820a37dfe9dfe4cab2b7b7460552d08e67dee8057ed5354eb68d8e3440890ae983ce3bee957d2b45684950b454a2b6d71d5ee77c1fd3fddc022e2a510337f - languageName: node - linkType: hard - "@scure/base@npm:~1.1.8": version: 1.1.8 resolution: "@scure/base@npm:1.1.8" @@ -2163,6 +2156,13 @@ __metadata: languageName: node linkType: hard +"@scure/base@npm:~1.2.1": + version: 1.2.1 + resolution: "@scure/base@npm:1.2.1" + checksum: 061e04e4f6ed7bada6cdad4c799e6a82f30dda3f4008895bdb2e556f333f9b41f44dc067d25c064357ed6c012ea9c8be1e7927caf8a083af865b8de27b52370c + languageName: node + linkType: hard + "@scure/bip32@npm:1.1.5": version: 1.1.5 resolution: "@scure/bip32@npm:1.1.5" @@ -2207,14 +2207,14 @@ __metadata: languageName: node linkType: hard -"@scure/bip32@npm:1.5.0": - version: 1.5.0 - resolution: "@scure/bip32@npm:1.5.0" +"@scure/bip32@npm:1.6.0, @scure/bip32@npm:^1.5.0": + version: 1.6.0 + resolution: "@scure/bip32@npm:1.6.0" dependencies: - "@noble/curves": ~1.6.0 - "@noble/hashes": ~1.5.0 - "@scure/base": ~1.1.7 - checksum: 2e119525cdffccc3aad7ca64aec22df2101233708111dfb551410f82aae85fe14acf39dc87cea1a535adc327451f9c3dea3c6a2dd22b859508025bc46a7a80ce + "@noble/curves": ~1.7.0 + "@noble/hashes": ~1.6.0 + "@scure/base": ~1.2.1 + checksum: 1347477e28678a9bc4e2ec5e8e0f679263f2e3cb19c0e65849f76810c4c608461d4b283521c897249fa7dacc8c76e1b50e2a866b22467c8e93662a9c545cd42b languageName: node linkType: hard @@ -2258,6 +2258,16 @@ __metadata: languageName: node linkType: hard +"@scure/bip39@npm:1.5.0, @scure/bip39@npm:^1.4.0": + version: 1.5.0 + resolution: "@scure/bip39@npm:1.5.0" + dependencies: + "@noble/hashes": ~1.6.0 + "@scure/base": ~1.2.1 + checksum: 03d1888f5d0d514eebc5c3adc1e071d225963d434fcf789abea5ef2c8b4b99f3ad9ebee8a597c0c13d5415e6b2b380f55f61560c1643cd871961ab91cbcf5122 + languageName: node + linkType: hard + "@se-2/hardhat@workspace:packages/hardhat": version: 0.0.0-use.local resolution: "@se-2/hardhat@workspace:packages/hardhat" @@ -2335,8 +2345,8 @@ __metadata: typescript: <5.6.0 usehooks-ts: ^3.1.0 vercel: ^39.1.3 - viem: 2.21.32 - wagmi: 2.12.23 + viem: 2.21.54 + wagmi: 2.13.4 zustand: ^5.0.0 languageName: unknown linkType: soft @@ -3441,24 +3451,24 @@ __metadata: languageName: node linkType: hard -"@wagmi/connectors@npm:5.3.2": - version: 5.3.2 - resolution: "@wagmi/connectors@npm:5.3.2" +"@wagmi/connectors@npm:5.5.3": + version: 5.5.3 + resolution: "@wagmi/connectors@npm:5.5.3" dependencies: - "@coinbase/wallet-sdk": 4.1.0 - "@metamask/sdk": 0.30.1 - "@safe-global/safe-apps-provider": 0.18.3 + "@coinbase/wallet-sdk": 4.2.3 + "@metamask/sdk": 0.31.1 + "@safe-global/safe-apps-provider": 0.18.4 "@safe-global/safe-apps-sdk": 9.1.0 "@walletconnect/ethereum-provider": 2.17.0 cbw-sdk: "npm:@coinbase/wallet-sdk@3.9.3" peerDependencies: - "@wagmi/core": 2.14.1 + "@wagmi/core": 2.15.2 typescript: ">=5.0.4" viem: 2.x peerDependenciesMeta: typescript: optional: true - checksum: 32c7345ca9cdea09a12c3aa99d8554f75d3cec427fb023ea97afe45570f01685e744e9b894db6c7d746ef81dcaa5d6fcbdf78ac1a6ab4fa0cd60515489230c8b + checksum: 021f927acdbe40df9f6b625006d05333c97aee916e615b3671baaeb3b6c8ef53bf411cef802b244334a8d9e0f80dfafc56a00257324f8ff33acb1b43ad5757d5 languageName: node linkType: hard @@ -3482,9 +3492,9 @@ __metadata: languageName: node linkType: hard -"@wagmi/core@npm:2.14.1": - version: 2.14.1 - resolution: "@wagmi/core@npm:2.14.1" +"@wagmi/core@npm:2.15.2": + version: 2.15.2 + resolution: "@wagmi/core@npm:2.15.2" dependencies: eventemitter3: 5.0.1 mipd: 0.0.7 @@ -3498,7 +3508,7 @@ __metadata: optional: true typescript: optional: true - checksum: c77ca6cbb3904b52d1e93d08fee790cb872d5846d39de09c789a9f8aef40fec8399d5e44dd6394c2743fd3d73220c819ffdc957d09ec8948eb599f73c62a85bd + checksum: 42a8fc938bb3f8f878c827b7c7f3fc08b808155a6f38e5a969bdd16b1437efc217465b33ccbcb9dc1138211cdbb79d17a2f14a80a3183bf6e74f0b53b43afd8b languageName: node linkType: hard @@ -3903,6 +3913,21 @@ __metadata: languageName: node linkType: hard +"abitype@npm:1.0.7, abitype@npm:^1.0.6": + version: 1.0.7 + resolution: "abitype@npm:1.0.7" + peerDependencies: + typescript: ">=5.0.4" + zod: ^3 >=3.22.0 + peerDependenciesMeta: + typescript: + optional: true + zod: + optional: true + checksum: c3b3ee19becbbce1d5c55a40a13dee6c09c0d710eee9c601433eb496c5ee2cd39e97dd0d043fa1ff7e68b1239ef83fe56951b2009d467e989fe941785cd7f8b8 + languageName: node + linkType: hard + "abort-controller@npm:^3.0.0": version: 3.0.0 resolution: "abort-controller@npm:3.0.0" @@ -5815,15 +5840,15 @@ __metadata: languageName: node linkType: hard -"eciesjs@npm:^0.4.8": - version: 0.4.9 - resolution: "eciesjs@npm:0.4.9" +"eciesjs@npm:^0.4.11": + version: 0.4.12 + resolution: "eciesjs@npm:0.4.12" dependencies: - "@ecies/ciphers": ^0.2.0 + "@ecies/ciphers": ^0.2.1 "@noble/ciphers": ^1.0.0 "@noble/curves": ^1.6.0 "@noble/hashes": ^1.5.0 - checksum: 288a987a120a2ccc947c6bec220e5047505df260af43e258526a2e1fdb2edef9fd2b097544cb2c18ad5829c5a627355d067acd8d50833ef02a4af4581da0d4c4 + checksum: ef98528b8af23b013dd432b43cc1a378d58621f887a7db234ebc997006e16ab9ffa0ea973bf2195aa63dbfa996afa9e3a8f8410b6e3d5c3808365a3d02b1141a languageName: node linkType: hard @@ -6340,13 +6365,6 @@ __metadata: languageName: node linkType: hard -"escape-string-regexp@npm:2.0.0": - version: 2.0.0 - resolution: "escape-string-regexp@npm:2.0.0" - checksum: 9f8a2d5743677c16e85c810e3024d54f0c8dea6424fad3c79ef6666e81dd0846f7437f5e729dfcdac8981bc9e5294c39b4580814d114076b8d36318f46ae4395 - languageName: node - linkType: hard - "escape-string-regexp@npm:4.0.0, escape-string-regexp@npm:^4.0.0": version: 4.0.0 resolution: "escape-string-regexp@npm:4.0.0" @@ -6944,7 +6962,7 @@ __metadata: languageName: node linkType: hard -"eventemitter2@npm:^6.4.7": +"eventemitter2@npm:^6.4.9": version: 6.4.9 resolution: "eventemitter2@npm:6.4.9" checksum: be59577c1e1c35509c7ba0e2624335c35bbcfd9485b8a977384c6cc6759341ea1a98d3cb9dbaa5cea4fff9b687e504504e3f9c2cc1674cf3bd8a43a7c74ea3eb @@ -8235,24 +8253,6 @@ __metadata: languageName: node linkType: hard -"i18next-browser-languagedetector@npm:7.1.0": - version: 7.1.0 - resolution: "i18next-browser-languagedetector@npm:7.1.0" - dependencies: - "@babel/runtime": ^7.19.4 - checksum: 36981b9a9995ed66387f3735cceffe107ed3cdb6ca278d45fa243fabc65669c0eca095ed4a55a93dac046ca1eb23fd986ec0079723be7ebb8505e6ba25f379bb - languageName: node - linkType: hard - -"i18next@npm:23.11.5": - version: 23.11.5 - resolution: "i18next@npm:23.11.5" - dependencies: - "@babel/runtime": ^7.23.2 - checksum: e9ec83703af59205af81f10929fd420314c0c976d1f4c42a191dc4d13f1284d13517105325286772571292953839c7183baa92e9bb43f41efe87dbc50c9aed1c - languageName: node - linkType: hard - "iconv-lite@npm:0.4.24": version: 0.4.24 resolution: "iconv-lite@npm:0.4.24" @@ -8386,7 +8386,7 @@ __metadata: languageName: node linkType: hard -"invariant@npm:2.2.4, invariant@npm:^2.2.4": +"invariant@npm:^2.2.4": version: 2.2.4 resolution: "invariant@npm:2.2.4" dependencies: @@ -10579,6 +10579,26 @@ __metadata: languageName: node linkType: hard +"ox@npm:0.1.2": + version: 0.1.2 + resolution: "ox@npm:0.1.2" + dependencies: + "@adraffy/ens-normalize": ^1.10.1 + "@noble/curves": ^1.6.0 + "@noble/hashes": ^1.5.0 + "@scure/bip32": ^1.5.0 + "@scure/bip39": ^1.4.0 + abitype: ^1.0.6 + eventemitter3: 5.0.1 + peerDependencies: + typescript: ">=5.4.0" + peerDependenciesMeta: + typescript: + optional: true + checksum: 3f01119adbec8258b064298c66cb9830fc32c023e7fdc6e0634610505e74e8aab051c7fa49dad0fdd751a1c4af66c8eb2a825d993c6e79611e761a537276afd6 + languageName: node + linkType: hard + "p-finally@npm:^2.0.0": version: 2.0.1 resolution: "p-finally@npm:2.0.1" @@ -11067,6 +11087,13 @@ __metadata: languageName: node linkType: hard +"preact@npm:^10.24.2": + version: 10.25.1 + resolution: "preact@npm:10.25.1" + checksum: 7b31f82acfc5eaccc70c19b55ff2bc8edb3d636dfb84e254c9258871c69e1652876efe4bb3a5f21bf521386b001bc6c8831e535d41eecbe0f31c13a0e2a062a3 + languageName: node + linkType: hard + "prelude-ls@npm:^1.2.1": version: 1.2.1 resolution: "prelude-ls@npm:1.2.1" @@ -11209,31 +11236,6 @@ __metadata: languageName: node linkType: hard -"qr-code-styling@npm:^1.6.0-rc.1": - version: 1.6.0-rc.1 - resolution: "qr-code-styling@npm:1.6.0-rc.1" - dependencies: - qrcode-generator: ^1.4.3 - checksum: 778754790fe0b586ecd38fb02de777c7dd9cf844cf6e3c88f9a23ad85b122200a8567c946e3c41dba84ddd2f0016aa31ddfd1507150e1dbfea8a58323b62d944 - languageName: node - linkType: hard - -"qrcode-generator@npm:^1.4.3": - version: 1.4.4 - resolution: "qrcode-generator@npm:1.4.4" - checksum: 860cfdd2a7a608d34e92cab99774cc08182e1911432f30ed36d16f8a5cdabd7fdf40239caed91fa2691cfe66c8d95c1340a2fc9cc439eed07a9f2eb328c6f527 - languageName: node - linkType: hard - -"qrcode-terminal-nooctal@npm:^0.12.1": - version: 0.12.1 - resolution: "qrcode-terminal-nooctal@npm:0.12.1" - bin: - qrcode-terminal: bin/qrcode-terminal.js - checksum: 1071c4be2bfa07b3956ad0a63c87452ced0b5180a9dc19f224fc3dd69bb24ad687a7af365acdde0f876ddf89dc1a4beadba88d89c7c5c5cbf2ef3efaef64736e - languageName: node - linkType: hard - "qrcode.react@npm:^4.0.1": version: 4.0.1 resolution: "qrcode.react@npm:4.0.1" @@ -11388,19 +11390,6 @@ __metadata: languageName: node linkType: hard -"react-native-webview@npm:^11.26.0": - version: 11.26.1 - resolution: "react-native-webview@npm:11.26.1" - dependencies: - escape-string-regexp: 2.0.0 - invariant: 2.2.4 - peerDependencies: - react: "*" - react-native: "*" - checksum: d2f95a89e944a2f1e8cf402e4e274f3568edae42e7ef190915e9fba8004a01d699c962459bdc9688c159060538e90aea3017cab24e6f4112021cbbc10ef57104 - languageName: node - linkType: hard - "react-remove-scroll-bar@npm:^2.3.4": version: 2.3.4 resolution: "react-remove-scroll-bar@npm:2.3.4" @@ -13065,6 +13054,13 @@ __metadata: languageName: node linkType: hard +"tslib@npm:^2.6.0": + version: 2.8.1 + resolution: "tslib@npm:2.8.1" + checksum: e4aba30e632b8c8902b47587fd13345e2827fa639e7c3121074d5ee0880723282411a8838f830b55100cbe4517672f84a2472667d355b81e8af165a55dc6203a + languageName: node + linkType: hard + "tslib@npm:^2.6.2": version: 2.7.0 resolution: "tslib@npm:2.7.0" @@ -13704,17 +13700,17 @@ __metadata: languageName: node linkType: hard -"viem@npm:2.21.32": - version: 2.21.32 - resolution: "viem@npm:2.21.32" +"viem@npm:2.21.54": + version: 2.21.54 + resolution: "viem@npm:2.21.54" dependencies: - "@adraffy/ens-normalize": 1.11.0 - "@noble/curves": 1.6.0 - "@noble/hashes": 1.5.0 - "@scure/bip32": 1.5.0 - "@scure/bip39": 1.4.0 - abitype: 1.0.6 + "@noble/curves": 1.7.0 + "@noble/hashes": 1.6.1 + "@scure/bip32": 1.6.0 + "@scure/bip39": 1.5.0 + abitype: 1.0.7 isows: 1.0.6 + ox: 0.1.2 webauthn-p256: 0.0.10 ws: 8.18.0 peerDependencies: @@ -13722,7 +13718,7 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: da9e623651ceebd9cae0e35eba9b3d226622b6dfbfcc656f905e522c650c691316247d9536681cf7710cf33a4c95dcf11b640ce04c56f374c60addafba0fb8d9 + checksum: 594aacd4c8f9b0fd8c99a7fe2a936c9b6ea0851d05b206b24d4903e0cbbf811c5795dd79ba5a9fdb21e40c996440cb114321b65142f00cf06a20f89a0b51d894 languageName: node linkType: hard @@ -13790,12 +13786,12 @@ __metadata: languageName: node linkType: hard -"wagmi@npm:2.12.23": - version: 2.12.23 - resolution: "wagmi@npm:2.12.23" +"wagmi@npm:2.13.4": + version: 2.13.4 + resolution: "wagmi@npm:2.13.4" dependencies: - "@wagmi/connectors": 5.3.2 - "@wagmi/core": 2.14.1 + "@wagmi/connectors": 5.5.3 + "@wagmi/core": 2.15.2 use-sync-external-store: 1.2.0 peerDependencies: "@tanstack/react-query": ">=5.0.0" @@ -13805,7 +13801,7 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 6d20d0ad1f1d94e9dbb73dc3e678dbffe5eb4cceb5443824608d6b6274b13329b9b9855fb9795dc72ec69cf629925b57e0d069deebcdd0987798f292034a762e + checksum: 22cd61928b73579e2bfbf63da21fd55b565acc351802978b73ab40b77480c631d21a5188c083046728de851969898bb942ee164b46b83ac8a95e11e9ac2ec6a6 languageName: node linkType: hard From acdea005426d947bf5346cc256addef2f133fae3 Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Wed, 11 Dec 2024 10:22:29 +0530 Subject: [PATCH 2/6] add changeset --- .changeset/eighty-ducks-tease.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/eighty-ducks-tease.md diff --git a/.changeset/eighty-ducks-tease.md b/.changeset/eighty-ducks-tease.md new file mode 100644 index 000000000..dbacf73a0 --- /dev/null +++ b/.changeset/eighty-ducks-tease.md @@ -0,0 +1,5 @@ +--- +"create-eth": patch +--- + +reverse rpc fallback order (https://github.com/scaffold-eth/scaffold-eth-2/pull/1010) From a88dd0424c739a4721b60e600f472ebddfeeab2d Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Wed, 11 Dec 2024 12:47:39 +0530 Subject: [PATCH 3/6] add default contract deployment --- .../packages/foundry/script/Deploy.s.sol.template.mjs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/templates/solidity-frameworks/foundry/packages/foundry/script/Deploy.s.sol.template.mjs b/templates/solidity-frameworks/foundry/packages/foundry/script/Deploy.s.sol.template.mjs index ea924b105..018e7ce21 100644 --- a/templates/solidity-frameworks/foundry/packages/foundry/script/Deploy.s.sol.template.mjs +++ b/templates/solidity-frameworks/foundry/packages/foundry/script/Deploy.s.sol.template.mjs @@ -17,6 +17,9 @@ contract DeployScript is ScaffoldETHDeploy { }`; export default withDefaults(content, { - deploymentsScriptsImports: "", - deploymentsLogic: "", + deploymentsScriptsImports: `import { DeployYourContract } from "./DeployYourContract.s.sol";`, + deploymentsLogic: ` + DeployYourContract deployYourContract = new DeployYourContract(); + deployYourContract.run(); + `, }); From 8c654419f7b87364eef8798a2ebd1d02b126133e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez?= Date: Wed, 11 Dec 2024 11:51:44 +0100 Subject: [PATCH 4/6] Encrypt deployer PK on .env file (when using hardhat) (#1008) --- package.json | 4 +- packages/hardhat/.env.example | 4 +- .../hardhat/deploy/00_deploy_your_contract.ts | 4 +- packages/hardhat/hardhat.config.ts | 3 +- packages/hardhat/package.json | 7 +- packages/hardhat/scripts/generateAccount.ts | 37 ++++++---- packages/hardhat/scripts/importAccount.ts | 72 +++++++++++++++++++ packages/hardhat/scripts/listAccount.ts | 19 +++-- .../hardhat/scripts/runHardhatDeployWithPK.ts | 58 +++++++++++++++ yarn.lock | 70 +++++++++++++++++- 10 files changed, 253 insertions(+), 25 deletions(-) create mode 100644 packages/hardhat/scripts/importAccount.ts create mode 100644 packages/hardhat/scripts/runHardhatDeployWithPK.ts diff --git a/package.json b/package.json index b0673bb15..1c49c957f 100644 --- a/package.json +++ b/package.json @@ -10,13 +10,15 @@ }, "scripts": { "account": "yarn workspace @se-2/hardhat account", + "account:import": "yarn workspace @se-2/hardhat account:import", + "account:generate": "yarn workspace @se-2/hardhat account:generate", "chain": "yarn workspace @se-2/hardhat chain", "fork": "yarn workspace @se-2/hardhat fork", "deploy": "yarn workspace @se-2/hardhat deploy", "verify": "yarn workspace @se-2/hardhat verify", "hardhat-verify": "yarn workspace @se-2/hardhat hardhat-verify", "compile": "yarn workspace @se-2/hardhat compile", - "generate": "yarn workspace @se-2/hardhat generate", + "generate": "yarn account:generate", "flatten": "yarn workspace @se-2/hardhat flatten", "hardhat:lint": "yarn workspace @se-2/hardhat lint", "hardhat:lint-staged": "yarn workspace @se-2/hardhat lint-staged", diff --git a/packages/hardhat/.env.example b/packages/hardhat/.env.example index 86614fe5e..b12938318 100644 --- a/packages/hardhat/.env.example +++ b/packages/hardhat/.env.example @@ -7,5 +7,7 @@ # To access the values stored in this .env file you can use: process.env.VARIABLENAME ALCHEMY_API_KEY= -DEPLOYER_PRIVATE_KEY= ETHERSCAN_MAINNET_API_KEY= + +# Don't fill this value manually, run yarn generate to generate a new account or yarn account:import to import an existing PK. +DEPLOYER_PRIVATE_KEY_ENCRYPTED= diff --git a/packages/hardhat/deploy/00_deploy_your_contract.ts b/packages/hardhat/deploy/00_deploy_your_contract.ts index 716fec79e..6478bd694 100644 --- a/packages/hardhat/deploy/00_deploy_your_contract.ts +++ b/packages/hardhat/deploy/00_deploy_your_contract.ts @@ -15,8 +15,8 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn When deploying to live networks (e.g `yarn deploy --network sepolia`), the deployer account should have sufficient balance to pay for the gas fees for contract creation. - You can generate a random account with `yarn generate` which will fill DEPLOYER_PRIVATE_KEY - with a random private key in the .env file (then used on hardhat.config.ts) + You can generate a random account with `yarn generate` or `yarn account:import` to import your + existing PK which will fill DEPLOYER_PRIVATE_KEY_ENCRYPTED in the .env file (then used on hardhat.config.ts) You can run the `yarn account` command to check your balance in every network. */ const { deployer } = await hre.getNamedAccounts(); diff --git a/packages/hardhat/hardhat.config.ts b/packages/hardhat/hardhat.config.ts index fd4a6d41a..0ea0bdf47 100644 --- a/packages/hardhat/hardhat.config.ts +++ b/packages/hardhat/hardhat.config.ts @@ -13,8 +13,9 @@ import { task } from "hardhat/config"; import generateTsAbis from "./scripts/generateTsAbis"; // If not set, it uses the hardhat account 0 private key. +// You can generate a random account with `yarn generate` or `yarn account:import` to import your existing PK const deployerPrivateKey = - process.env.DEPLOYER_PRIVATE_KEY ?? "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; + process.env.__RUNTIME_DEPLOYER_PRIVATE_KEY ?? "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; // If not set, it uses our block explorers default API keys. const etherscanApiKey = process.env.ETHERSCAN_MAINNET_API_KEY || "DNXJA8RX2Q3VZ4URQIWP7Z68CJXQZSC6AW"; const etherscanOptimisticApiKey = process.env.ETHERSCAN_OPTIMISTIC_API_KEY || "RM62RDISS1RH448ZY379NX625ASG1N633R"; diff --git a/packages/hardhat/package.json b/packages/hardhat/package.json index 2a17b3ebe..22184d753 100644 --- a/packages/hardhat/package.json +++ b/packages/hardhat/package.json @@ -3,12 +3,14 @@ "version": "0.0.1", "scripts": { "account": "hardhat run scripts/listAccount.ts", + "account:import": "hardhat run scripts/importAccount.ts", + "account:generate": "hardhat run scripts/generateAccount.ts", "chain": "hardhat node --network hardhat --no-deploy", "check-types": "tsc --noEmit --incremental", "compile": "hardhat compile", - "deploy": "hardhat deploy", + "deploy": "ts-node scripts/runHardhatDeployWithPK.ts", "fork": "MAINNET_FORKING_ENABLED=true hardhat node --network hardhat --no-deploy", - "generate": "hardhat run scripts/generateAccount.ts", + "generate": "yarn account:generate", "flatten": "hardhat flatten", "lint": "eslint --config ./.eslintrc.json --ignore-path ./.eslintignore ./*.ts ./deploy/**/*.ts ./scripts/**/*.ts ./test/**/*.ts", "lint-staged": "eslint --config ./.eslintrc.json --ignore-path ./.eslintignore", @@ -49,6 +51,7 @@ "typescript": "<5.6.0" }, "dependencies": { + "@inquirer/password": "^4.0.2", "@openzeppelin/contracts": "^5.0.2", "@typechain/ethers-v6": "^0.5.1", "dotenv": "^16.4.5", diff --git a/packages/hardhat/scripts/generateAccount.ts b/packages/hardhat/scripts/generateAccount.ts index 5de8e458c..be55d0576 100644 --- a/packages/hardhat/scripts/generateAccount.ts +++ b/packages/hardhat/scripts/generateAccount.ts @@ -1,42 +1,55 @@ import { ethers } from "ethers"; import { parse, stringify } from "envfile"; import * as fs from "fs"; +import password from "@inquirer/password"; const envFilePath = "./.env"; -/** - * Generate a new random private key and write it to the .env file - */ -const setNewEnvConfig = (existingEnvConfig = {}) => { - console.log("šŸ‘› Generating new Wallet"); +const getValidatedPassword = async () => { + while (true) { + const pass = await password({ message: "Enter a password to encrypt your private key:" }); + const confirmation = await password({ message: "Confirm password:" }); + + if (pass === confirmation) { + return pass; + } + console.log("āŒ Passwords don't match. Please try again."); + } +}; + +const setNewEnvConfig = async (existingEnvConfig = {}) => { + console.log("šŸ‘› Generating new Wallet\n"); const randomWallet = ethers.Wallet.createRandom(); + const pass = await getValidatedPassword(); + const encryptedJson = await randomWallet.encrypt(pass); + const newEnvConfig = { ...existingEnvConfig, - DEPLOYER_PRIVATE_KEY: randomWallet.privateKey, + DEPLOYER_PRIVATE_KEY_ENCRYPTED: encryptedJson, }; // Store in .env fs.writeFileSync(envFilePath, stringify(newEnvConfig)); - console.log("šŸ“„ Private Key saved to packages/hardhat/.env file"); - console.log("šŸŖ„ Generated wallet address:", randomWallet.address); + console.log("\nšŸ“„ Encrypted Private Key saved to packages/hardhat/.env file"); + console.log("šŸŖ„ Generated wallet address:", randomWallet.address, "\n"); + console.log("āš ļø Make sure to remember your password! You'll need it to decrypt the private key."); }; async function main() { if (!fs.existsSync(envFilePath)) { // No .env file yet. - setNewEnvConfig(); + await setNewEnvConfig(); return; } - // .env file exists const existingEnvConfig = parse(fs.readFileSync(envFilePath).toString()); - if (existingEnvConfig.DEPLOYER_PRIVATE_KEY) { + if (existingEnvConfig.DEPLOYER_PRIVATE_KEY_ENCRYPTED) { console.log("āš ļø You already have a deployer account. Check the packages/hardhat/.env file"); return; } - setNewEnvConfig(existingEnvConfig); + await setNewEnvConfig(existingEnvConfig); } main().catch(error => { diff --git a/packages/hardhat/scripts/importAccount.ts b/packages/hardhat/scripts/importAccount.ts new file mode 100644 index 000000000..4af0815b7 --- /dev/null +++ b/packages/hardhat/scripts/importAccount.ts @@ -0,0 +1,72 @@ +import { ethers } from "ethers"; +import { parse, stringify } from "envfile"; +import * as fs from "fs"; +import password from "@inquirer/password"; + +const envFilePath = "./.env"; + +const getValidatedPassword = async () => { + while (true) { + const pass = await password({ message: "Enter a password to encrypt your private key:" }); + const confirmation = await password({ message: "Confirm password:" }); + + if (pass === confirmation) { + return pass; + } + console.log("āŒ Passwords don't match. Please try again."); + } +}; + +const getWalletFromPrivateKey = async () => { + while (true) { + const privateKey = await password({ message: "Paste your private key:" }); + try { + const wallet = new ethers.Wallet(privateKey); + return wallet; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + } catch (e) { + console.log("āŒ Invalid private key format. Please try again."); + } + } +}; + +const setNewEnvConfig = async (existingEnvConfig = {}) => { + console.log("šŸ‘› Importing Wallet\n"); + + const wallet = await getWalletFromPrivateKey(); + + const pass = await getValidatedPassword(); + const encryptedJson = await wallet.encrypt(pass); + + const newEnvConfig = { + ...existingEnvConfig, + DEPLOYER_PRIVATE_KEY_ENCRYPTED: encryptedJson, + }; + + // Store in .env + fs.writeFileSync(envFilePath, stringify(newEnvConfig)); + console.log("\nšŸ“„ Encrypted Private Key saved to packages/hardhat/.env file"); + console.log("šŸŖ„ Imported wallet address:", wallet.address, "\n"); + console.log("āš ļø Make sure to remember your password! You'll need it to decrypt the private key."); +}; + +async function main() { + if (!fs.existsSync(envFilePath)) { + // No .env file yet. + await setNewEnvConfig(); + return; + } + + const existingEnvConfig = parse(fs.readFileSync(envFilePath).toString()); + if (existingEnvConfig.DEPLOYER_PRIVATE_KEY_ENCRYPTED) { + console.log("āš ļø You already have a deployer account. Check the packages/hardhat/.env file"); + return; + } + + await setNewEnvConfig(existingEnvConfig); +} + +main().catch(error => { + console.error(error); + process.exitCode = 1; +}); diff --git a/packages/hardhat/scripts/listAccount.ts b/packages/hardhat/scripts/listAccount.ts index 4fc5f2da1..ae1aafd6f 100644 --- a/packages/hardhat/scripts/listAccount.ts +++ b/packages/hardhat/scripts/listAccount.ts @@ -3,17 +3,26 @@ dotenv.config(); import { ethers, Wallet } from "ethers"; import QRCode from "qrcode"; import { config } from "hardhat"; +import password from "@inquirer/password"; async function main() { - const privateKey = process.env.DEPLOYER_PRIVATE_KEY; + const encryptedKey = process.env.DEPLOYER_PRIVATE_KEY_ENCRYPTED; - if (!privateKey) { - console.log("šŸš«ļø You don't have a deployer account. Run `yarn generate` first"); + if (!encryptedKey) { + console.log("šŸš«ļø You don't have a deployer account. Run `yarn generate` or `yarn account:import` first"); + return; + } + + const pass = await password({ message: "Enter your password to decrypt the private key:" }); + let wallet: Wallet; + try { + wallet = (await Wallet.fromEncryptedJson(encryptedKey, pass)) as Wallet; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + } catch (e) { + console.log("āŒ Failed to decrypt private key. Wrong password?"); return; } - // Get account from private key. - const wallet = new Wallet(privateKey); const address = wallet.address; console.log(await QRCode.toString(address, { type: "terminal", small: true })); console.log("Public address:", address, "\n"); diff --git a/packages/hardhat/scripts/runHardhatDeployWithPK.ts b/packages/hardhat/scripts/runHardhatDeployWithPK.ts new file mode 100644 index 000000000..7628b4313 --- /dev/null +++ b/packages/hardhat/scripts/runHardhatDeployWithPK.ts @@ -0,0 +1,58 @@ +import * as dotenv from "dotenv"; +dotenv.config(); +import { Wallet } from "ethers"; +import password from "@inquirer/password"; +import { spawn } from "child_process"; +import { config } from "hardhat"; + +/** + * Unencrypts the private key and runs the hardhat deploy command + */ +async function main() { + const networkIndex = process.argv.indexOf("--network"); + const networkName = networkIndex !== -1 ? process.argv[networkIndex + 1] : config.defaultNetwork; + + if (networkName === "localhost" || networkName === "hardhat") { + // Deploy command on the localhost network + const hardhat = spawn("hardhat", ["deploy", ...process.argv.slice(2)], { + stdio: "inherit", + env: process.env, + shell: process.platform === "win32", + }); + + hardhat.on("exit", code => { + process.exit(code || 0); + }); + return; + } + + const encryptedKey = process.env.DEPLOYER_PRIVATE_KEY_ENCRYPTED; + + if (!encryptedKey) { + console.log("šŸš«ļø You don't have a deployer account. Run `yarn generate` or `yarn account:import` first"); + return; + } + + const pass = await password({ message: "Enter password to decrypt private key:" }); + + try { + const wallet = await Wallet.fromEncryptedJson(encryptedKey, pass); + process.env.__RUNTIME_DEPLOYER_PRIVATE_KEY = wallet.privateKey; + + const hardhat = spawn("hardhat", ["deploy", ...process.argv.slice(2)], { + stdio: "inherit", + env: process.env, + shell: process.platform === "win32", + }); + + hardhat.on("exit", code => { + process.exit(code || 0); + }); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + } catch (e) { + console.error("Failed to decrypt private key. Wrong password?"); + process.exit(1); + } +} + +main().catch(console.error); diff --git a/yarn.lock b/yarn.lock index 69eb84490..0a857132b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -894,6 +894,52 @@ __metadata: languageName: node linkType: hard +"@inquirer/core@npm:^10.1.0": + version: 10.1.0 + resolution: "@inquirer/core@npm:10.1.0" + dependencies: + "@inquirer/figures": ^1.0.8 + "@inquirer/type": ^3.0.1 + ansi-escapes: ^4.3.2 + cli-width: ^4.1.0 + mute-stream: ^2.0.0 + signal-exit: ^4.1.0 + strip-ansi: ^6.0.1 + wrap-ansi: ^6.2.0 + yoctocolors-cjs: ^2.1.2 + checksum: c52be9ef04497a2b82ed6b1258ebd24ad0950b4b83a96e6fbde1a801eeced4e4b32ed5b2217eac98e504cc1d16ddc8d9d39243c96bdb5390ff13629b28c96591 + languageName: node + linkType: hard + +"@inquirer/figures@npm:^1.0.8": + version: 1.0.8 + resolution: "@inquirer/figures@npm:1.0.8" + checksum: 24c5c70f49a5f0e9d38f5552fb6936c258d2fc545f6a4944b17ba357c9ca4a729e8cffd77666971554ebc2a57948cfe5003331271a259c406b3f2de0e9c559b7 + languageName: node + linkType: hard + +"@inquirer/password@npm:^4.0.2": + version: 4.0.2 + resolution: "@inquirer/password@npm:4.0.2" + dependencies: + "@inquirer/core": ^10.1.0 + "@inquirer/type": ^3.0.1 + ansi-escapes: ^4.3.2 + peerDependencies: + "@types/node": ">=18" + checksum: 69dc3986098cdfb4ed73653b690f7db7d88e483fdd9026b7308d1f6ff1208e5a7599f8c49910735e1fd8008fb367a9bf8f0ff80e7551831c6de15733980277af + languageName: node + linkType: hard + +"@inquirer/type@npm:^3.0.1": + version: 3.0.1 + resolution: "@inquirer/type@npm:3.0.1" + peerDependencies: + "@types/node": ">=18" + checksum: af412f1e7541d43554b02199ae71a2039a1bff5dc51ceefd87de9ece55b199682733b28810fb4b6cb3ed4a159af4cc4a26d4bb29c58dd127e7d9dbda0797d8e7 + languageName: node + linkType: hard + "@ioredis/commands@npm:^1.1.1": version: 1.2.0 resolution: "@ioredis/commands@npm:1.2.0" @@ -2274,6 +2320,7 @@ __metadata: dependencies: "@ethersproject/abi": ^5.7.0 "@ethersproject/providers": ^5.7.2 + "@inquirer/password": ^4.0.2 "@nomicfoundation/hardhat-chai-matchers": ^2.0.7 "@nomicfoundation/hardhat-ethers": ^3.0.8 "@nomicfoundation/hardhat-network-helpers": ^1.0.11 @@ -4104,7 +4151,7 @@ __metadata: languageName: node linkType: hard -"ansi-escapes@npm:^4.3.0": +"ansi-escapes@npm:^4.3.0, ansi-escapes@npm:^4.3.2": version: 4.3.2 resolution: "ansi-escapes@npm:4.3.2" dependencies: @@ -5097,6 +5144,13 @@ __metadata: languageName: node linkType: hard +"cli-width@npm:^4.1.0": + version: 4.1.0 + resolution: "cli-width@npm:4.1.0" + checksum: 0a79cff2dbf89ef530bcd54c713703ba94461457b11e5634bd024c78796ed21401e32349c004995954e06f442d82609287e7aabf6a5f02c919a1cf3b9b6854ff + languageName: node + linkType: hard + "client-only@npm:0.0.1": version: 0.0.1 resolution: "client-only@npm:0.0.1" @@ -9958,6 +10012,13 @@ __metadata: languageName: node linkType: hard +"mute-stream@npm:^2.0.0": + version: 2.0.0 + resolution: "mute-stream@npm:2.0.0" + checksum: d2e4fd2f5aa342b89b98134a8d899d8ef9b0a6d69274c4af9df46faa2d97aeb1f2ce83d867880d6de63643c52386579b99139801e24e7526c3b9b0a6d1e18d6c + languageName: node + linkType: hard + "mz@npm:^2.7.0": version: 2.7.0 resolution: "mz@npm:2.7.0" @@ -14345,6 +14406,13 @@ __metadata: languageName: node linkType: hard +"yoctocolors-cjs@npm:^2.1.2": + version: 2.1.2 + resolution: "yoctocolors-cjs@npm:2.1.2" + checksum: 1c474d4b30a8c130e679279c5c2c33a0d48eba9684ffa0252cc64846c121fb56c3f25457fef902edbe1e2d7a7872130073a9fc8e795299d75e13fa3f5f548f1b + languageName: node + linkType: hard + "zksync-ethers@npm:^5.0.0": version: 5.9.2 resolution: "zksync-ethers@npm:5.9.2" From 5680dd9f84ff025af31e27d6dea78d3a55fec94b Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Wed, 11 Dec 2024 18:46:42 +0530 Subject: [PATCH 5/6] fix hardhat.config template string with espace backticks --- .../hardhat/packages/hardhat/hardhat.config.ts.template.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/solidity-frameworks/hardhat/packages/hardhat/hardhat.config.ts.template.mjs b/templates/solidity-frameworks/hardhat/packages/hardhat/hardhat.config.ts.template.mjs index 421cc40a5..3e35b4a50 100644 --- a/templates/solidity-frameworks/hardhat/packages/hardhat/hardhat.config.ts.template.mjs +++ b/templates/solidity-frameworks/hardhat/packages/hardhat/hardhat.config.ts.template.mjs @@ -36,7 +36,7 @@ ${imports.filter(Boolean).join("\n")} // 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. -// You can generate a random account with `yarn generate` or `yarn account:import` to import your existing PK +// You can generate a random account with \`yarn generate\` or \`yarn account:import\` to import your existing PK const deployerPrivateKey = process.env.__RUNTIME_DEPLOYER_PRIVATE_KEY ?? "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; // If not set, it uses our block explorers default API keys. From 432ea782b9fb5f5b656ce982b9934030bfa929ff Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Wed, 11 Dec 2024 18:58:11 +0530 Subject: [PATCH 6/6] update changeset --- .changeset/eighty-ducks-tease.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.changeset/eighty-ducks-tease.md b/.changeset/eighty-ducks-tease.md index dbacf73a0..3be92c1a5 100644 --- a/.changeset/eighty-ducks-tease.md +++ b/.changeset/eighty-ducks-tease.md @@ -2,4 +2,5 @@ "create-eth": patch --- -reverse rpc fallback order (https://github.com/scaffold-eth/scaffold-eth-2/pull/1010) +- reverse rpc fallback order (https://github.com/scaffold-eth/scaffold-eth-2/pull/1010) +- Encrypt deployer PK on .env file (when using hardhat) (https://github.com/scaffold-eth/scaffold-eth-2/pull/1008 )