From c72bf8905bbb9198e6082e583a69295ca291db58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BC=86=E5=9E=A3=E7=9A=93=E5=A4=A7?= Date: Sun, 25 Aug 2024 07:47:57 +0900 Subject: [PATCH] event detectioin --- packages/hardhat/test/YourContract.ts | 10 ++++----- packages/nextjs/app/api/server.tsx | 30 +++++++++++++-------------- packages/nextjs/app/map/page.tsx | 15 +++++++++++++- packages/nextjs/scaffold.config.ts | 2 +- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/packages/hardhat/test/YourContract.ts b/packages/hardhat/test/YourContract.ts index a44cf04..1914e39 100644 --- a/packages/hardhat/test/YourContract.ts +++ b/packages/hardhat/test/YourContract.ts @@ -1,15 +1,15 @@ import { expect } from "chai"; import { ethers } from "hardhat"; -import { YourContract } from "../typechain-types"; +import { ZkTreasure } from "../typechain-types"; -describe("YourContract", function () { +describe("ZkTreasure", function () { // We define a fixture to reuse the same setup in every test. - let yourContract: YourContract; + let yourContract: ZkTreasure; before(async () => { const [owner] = await ethers.getSigners(); - const yourContractFactory = await ethers.getContractFactory("YourContract"); - yourContract = (await yourContractFactory.deploy(owner.address)) as YourContract; + const yourContractFactory = await ethers.getContractFactory("ZkTreasure"); + yourContract = (await yourContractFactory.deploy(owner.address)) as ZkTreasure; await yourContract.waitForDeployment(); }); diff --git a/packages/nextjs/app/api/server.tsx b/packages/nextjs/app/api/server.tsx index 0b34207..ad3c3ee 100644 --- a/packages/nextjs/app/api/server.tsx +++ b/packages/nextjs/app/api/server.tsx @@ -1,18 +1,18 @@ -import { useScaffoldWatchContractEvent } from "../../hooks/scaffold-eth"; +// import { useScaffoldWatchContractEvent } from "../../hooks/scaffold-eth"; -function Server() { - useScaffoldWatchContractEvent({ - contractName: "zkTreasure", - eventName: "CoordinateCreated", +// function Server() { +// useScaffoldWatchContractEvent({ +// contractName: "zkTreasure", +// eventName: "CoordinateCreated", - onLogs: logs => { - logs.map(log => { - const { coordinateId, player, x, y } = log.args; - console.log("📡 CoordinateCreated event:", coordinateId, player, x, y); - }); - // execute verification - }, - }); -} +// onLogs: logs => { +// logs.map(log => { +// const { coordinateId, player, x, y } = log.args; +// console.log("📡 CoordinateCreated event:", coordinateId, player, x, y); +// }); +// // execute verification +// }, +// // }); +// // } -export default Server; +// export default Server; diff --git a/packages/nextjs/app/map/page.tsx b/packages/nextjs/app/map/page.tsx index fe3c4b0..3ca757c 100644 --- a/packages/nextjs/app/map/page.tsx +++ b/packages/nextjs/app/map/page.tsx @@ -1,7 +1,7 @@ "use client"; import React, { useEffect, useState } from "react"; -import { useScaffoldWriteContract } from "~~/hooks/scaffold-eth"; +import { useScaffoldWatchContractEvent, useScaffoldWriteContract } from "~~/hooks/scaffold-eth"; // Function to transform coordinates to integers const transformCoordinatesToIntegers = (latitude: number, longitude: number) => { @@ -35,6 +35,19 @@ export default function GeolocationMapPage() { }; }, []); + useScaffoldWatchContractEvent({ + contractName: "zkTreasure", + eventName: "CoordinateCreated", + + onLogs: logs => { + logs.map(log => { + const { coordinateId, player, x, y } = log.args; + console.log("📡 CoordinateCreated event:", coordinateId, player, x, y); + }); + // execute verification + }, + }); + const initializeMap = () => { if (window.google) { const map = new window.google.maps.Map(document.getElementById("map")!, { diff --git a/packages/nextjs/scaffold.config.ts b/packages/nextjs/scaffold.config.ts index 4953807..b00a22e 100644 --- a/packages/nextjs/scaffold.config.ts +++ b/packages/nextjs/scaffold.config.ts @@ -10,7 +10,7 @@ export type ScaffoldConfig = { const scaffoldConfig = { // The networks on which your DApp is live - targetNetworks: [chains.sepolia, chains.hardhat], + targetNetworks: [chains.sepolia], // The interval at which your front-end polls the RPC servers for new data // it has no effect if you only target the local network (default is 4000)