Skip to content

Hardhat3

初始化

bash
npx hardhat --init

配置rpc url和private key

使用dotenv

bash
npm install dotenv
js
// 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-enc
sh
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 continue
js
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

Hardhat3 合约部署

使用Ignition

official Docs