Nextry = Next.js + Foundry
Frontend: Next.js 15RC
+ Shadcn
+ Wagmi/Wagmi cli
+ Rainbowkit
Solidity: Foundry
首先设置环境变量
cp next/.env.example next/.env
cp foundry/.env.example foundry/.env
pnpm run anvil
打开本地链pnpm run deploy
部署 foundry 合约到本地链,并将abi
和address
同步给前端pnpm run dev
运行 next.js 前端
一定要在 foundry/.env
中添加私钥 DEPLOYER_PRIVATE_KEY
和 ALCHEMY_API_KEY
变量,想要 verify 成功的话,还要有 ETHERSCAN_API_KEY
# https://docs.alchemy.com/docs/alchemy-quickstart-guide#1key-create-an-alchemy-api-key
ALCHEMY_API_KEY=
# https://etherscan.io/myapikey
ETHERSCAN_API_KEY=
DEPLOYER_PRIVATE_KEY=0x
执行
pnpm run deploy:sepolia
verify contract 需要科学网络环境,如果没有成功,可以用类似下边的命令重新验证
forge verify-contract <address> OurToken --chain-id 11155111
进入 foundry 目录
forge install OpenZeppelin/openzeppelin-contracts --no-commit
- Add
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
in remappings.txt
forge install smartcontractkit/chainlink-brownie-contracts --no-commit
- Add
@chainlink/contracts/=lib/chainlink-brownie-contracts/contracts/src/
in remapping.txt
-
Metamask 导入钱包 Anvil 默认账号助记词
test test test test test test test test test test test junk
-
给 Metamask 添加 Anvil 网络
网络名称: Anvil RPC URL: http://127.0.0.1:8545 链ID: 31337 货币符号: ETH
如遇不能保存,先
pnpm run anvil
本地运行 Anvil 链,再保存