Skip to content

Commit c339650

Browse files
committed
Add study notes for 2025-08-15
1 parent 5197a3e commit c339650

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

RowanWang6.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,89 @@ Web2金融行业转型中,做kyc以及反洗钱,对这方面比较感兴趣
1515
## Notes
1616

1717
<!-- Content_START -->
18+
# 2025-08-15
19+
20+
##React + Wagmi + Anvil 改造计划
21+
把现有的React/Vue + wagmi/web3.js + hardhat改造,看上去只需要修改anvil,但坑好多。
22+
23+
##改造步骤
24+
25+
1. 替换 Hardhat 网络为 Anvil
26+
27+
```
28+
#安装 Foundry (包含 Anvil)
29+
curl -L https://foundry.paradigm.xyz | bash
30+
foundryup
31+
```
32+
33+
2. 修改开发流程
34+
35+
// package.json 新增脚本
36+
{
37+
"scripts": {
38+
"anvil": "anvil --host 0.0.0.0 --port 8545 --accounts 10 --balance 10000",
39+
"dev:full": "concurrently \"npm run anvil\" \"npm run dev\" \"cd frontend-react
40+
&& npm run dev\""
41+
}
42+
}
43+
44+
3. 更新 Wagmi 配置
45+
46+
// frontend-react/src/config/wagmi.ts
47+
import { createConfig, http } from 'wagmi'
48+
import { foundry } from 'wagmi/chains'
49+
import { injected, metaMask, safe, walletConnect } from 'wagmi/connectors'
50+
51+
export const config = createConfig({
52+
chains: [foundry],
53+
connectors: [
54+
injected(),
55+
metaMask(),
56+
safe(),
57+
],
58+
transports: {
59+
[foundry.id]: http('http://127.0.0.1:8545'),
60+
},
61+
})
62+
63+
4. 优化部署脚本
64+
65+
// scripts/anvil-deploy.js
66+
const hre = require("hardhat");
67+
68+
async function main() {
69+
// 使用 Anvil 的固定地址进行部署
70+
const [deployer] = await hre.ethers.getSigners();
71+
console.log("Deploying with account:", deployer.address);
72+
73+
const MyToken = await hre.ethers.getContractFactory("MyToken");
74+
const token = await MyToken.deploy();
75+
76+
console.log("Token deployed to:", await token.getAddress());
77+
}
78+
79+
80+
5. 改进 DX (开发者体验)
81+
82+
// frontend-react/src/hooks/useContract.ts
83+
import { useReadContract, useWriteContract } from 'wagmi'
84+
import { CONTRACT_ADDRESS, CONTRACT_ABI } from '../config/wagmi'
85+
86+
export function useTokenContract() {
87+
const { writeContract } = useWriteContract()
88+
89+
const mint = (to: string, amount: bigint) => {
90+
return writeContract({
91+
address: CONTRACT_ADDRESS,
92+
abi: CONTRACT_ABI,
93+
functionName: 'mint',
94+
args: [to, amount],
95+
})
96+
}
97+
98+
return { mint }
99+
}
100+
18101
# 2025-08-14
19102

20103
https://github.com/RowanWang6/hardhat-beibei-coin-tutorialDapp

0 commit comments

Comments
 (0)