Appearance
Hardhat3
初始化
bash
npx hardhat --init配置rpc url和private key
使用dotenv
bash
npm install dotenvjs
// hardhat.config.js
import dotenv from 'dotenv';
dotenv.config();sh
# .env
SEPOLIA_RPC_URL=your_rpc_url
SEPOLIA_PRIVATE_KEY=your_private_key使用env-enc加密.env
bash
npm install --save-dev @chainlink/env-encsh
npx env-enc set-pw
Enter the password (input will be hidden): *********sh
➜ npx env-enc set
Please enter the variable name (or press ENTER to finish):
SEPOLIA_RPC_URL
Please enter the variable value (input will be hidden):
*******************************************************
Would you like to set another variable? Please enter the variable name (or press ENTER to finish):
SEPOLIA_PRIVATE_KEY
Please enter the variable value (input will be hidden):
****************************************************************需要查看之前输入的值:
sh
➜ npx env-enc set-pw
Enter the password (input will be hidden): *********
➜ npx env-enc view
The following variables are encrypted and stored in
SEPOLIA_RPC_URL =
SEPOLIA_PRIVATE_KEY =
Press ENTER to continuejs
import * as envEnc from "@chainlink/env-enc";
envEnc.config();
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL;
const SEPOLIA_PRIVATE_KEY = process.env.SEPOLIA_PRIVATE_KEY;hardhat3
sh
pnpm/npx hardhat keystore set SEPOLIA_RPC_URL
pnpm/npx hardhat keystore set SEPOLIA_PRIVATE_KEY