# Alchemy第八周教程 **Published by:** [NicWong nicwwd.lens(📦,💫)(🌸, 🌿)](https://paragraph.com/@nicwong-nicwwd-lens/) **Published on:** 2022-08-20 **URL:** https://paragraph.com/@nicwong-nicwwd-lens/alchemy ## Content Step1 建立测试网络 1.到Alchemy新建一个Optimism Goerli测试网络 2.这个网页不要关闭,等会要填url到.env(不过 这里有个问题,因为我用的是eth的Goerli测试网,实际上这一步不知道对不对,大家自己试试。不行就换过来,嘿嘿) Step 2 Clone代码 1.先到代码库用为自己建立一个分叉 1.在项目文件夹点击右键,打开git bash 2.在MINGW64输入 git clone https://github.com/nicwwd/ROAD3_WEEK08.git Step3 修改配置文件 1.用vscode打开ROAD3_WEEK08文件夹 2.新建一个.env文件,填写上一步的网址和开发钱包的私钥 REACT_APP_ALCHEMY_API_URL= REACT_APP_PRIVATE_KEY= 3.编辑hardhat.config.js 第一行改为 require("@nomicfoundation/hardhat-toolbox"); 4.打开CMD配置环境 按顺序执行一下命令 cd ROAD3_WEEK08 npm update npm install dotenv npm install yarn npm install hardhat npm install @nomicfoundation/hardhat-toolbox 5.部署合约 yarn hardhat console --network optimism 因为添加了console,cmd就进入了控制台 6.查看一下是不是自己的钱包 signer = await ethers.getSigner(); 7.查询钱包余额 balance0 = await ethers.provider.getBalance((await ethers.getSigner()).address) 返回钱包余额 8.依次执行三行命令 factory = ethers.getContractFactory("Casino") factory = await factory casino = await factory.deploy() 这样就开始部署合约了。 最后出来合约地址 到Goerli区块浏览器输入地址查询合约,目前Optimism Goerli是没有区块浏览器的,正好我也没有用Optimism Goerli的测试网,所以。。。当然大家也可以用Optimism主网来做。 Step4 测试游戏 const valA = ethers.utils.keccak256(0xBAD060A7) const hashA = ethers.utils.keccak256(valA) const valBwin = ethers.utils.keccak256(0x600D60A7) tx1 = await casino.proposeBet(hashA,{ value: 1e5}) 然后执行第二个 tx2 = await casino.acceptBet(hashA, valBwin, {value: 1e5}) 到链上看看就可以了。 最后可以上传到github,找找前面的教程 然后提交第八周表格 如果错了不要找我维权!!!!!! ## Publication Information - [NicWong nicwwd.lens(📦,💫)(🌸, 🌿)](https://paragraph.com/@nicwong-nicwwd-lens/): Publication homepage - [All Posts](https://paragraph.com/@nicwong-nicwwd-lens/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@nicwong-nicwwd-lens): Subscribe to updates - [Twitter](https://twitter.com/nicwwd): Follow on Twitter