diff --git a/.env.example b/.env.example
index 3514bd8..b6d9af6 100644
--- a/.env.example
+++ b/.env.example
@@ -1,3 +1,3 @@
-PRISMA_URL="Url comes here"
+PRISMA_URL="posgresql://postgres:treasurehunt_123_@db.siecxsbqymysnrfdinzh.supabase.co.5432/postgres"
NEXT_PUBLIC_SITE_URL=http://localhost:3000
NEXTAUTH_SECRET=secretishere
\ No newline at end of file
diff --git a/.well-known/brave-rewards-verification.txt b/.well-known/brave-rewards-verification.txt
new file mode 100644
index 0000000..c723e1b
--- /dev/null
+++ b/.well-known/brave-rewards-verification.txt
@@ -0,0 +1,4 @@
+This is a Brave Creators publisher verification file.
+
+Domain: treasure-hunt-five.vercel.app
+Token: e536af5c3ac28ee1ceaf866deab98665c7946837b1d0445e60ca64d602b58310
diff --git a/app/_components/BtnStartGame.js b/app/_components/BtnStartGame.js
index ba82b67..a03803f 100644
--- a/app/_components/BtnStartGame.js
+++ b/app/_components/BtnStartGame.js
@@ -5,6 +5,9 @@ import useSound from "./useSound";
import { useEffect } from "react";
const BtnStartGame = () => {
+ const walletAddress =
+ typeof window !== "undefined" ? localStorage.getItem("account") : null;
+
// const bgMusic = useSound("bg");
// useEffect(() => {
// window.addEventListener("click", () => {
@@ -20,7 +23,7 @@ const BtnStartGame = () => {
className="hover relative h-[80px] w-[80px] md:h-[100px] md:w-[100px]"
style={{ top: "38%", left: "5px" }}
>
-
+
{
bgMusic.play();
return () => {
@@ -62,6 +73,38 @@ function GameScreen({ id, screen = "screen1", items = dummyItems }) {
bgMusic.currentTime = 0;
};
}, []);
+
+ useEffect(() => {
+ async function initContract() {
+ const contract = getContract(
+ "0xfB40daE09C54ec8eB653f8cb140e0569202e3ac2",
+ Lock.abi,
+ 0
+ );
+ setContract(contract);
+ }
+ initContract();
+ }, []);
+
+ async function sendETH(walletAddress, amountToSend) {
+ try {
+ if (!contract) return;
+ const tx = await contract.sendEther(walletAddress, amountToSend, {
+ gasLimit: 50000,
+ });
+ const receipt = await tx.wait();
+ const transactionHash = receipt.transactionHash;
+ console.log("Transaction Hash:", transactionHash);
+ if (receipt.status === 1) {
+ console.log("ETH sent successfully!");
+ } else {
+ console.error("Transaction failed");
+ }
+ } catch (error) {
+ console.error(error);
+ }
+ }
+
const winSound = useSound("win", 0, 1, false);
const height = 672;
const router = useRouter();
@@ -76,7 +119,10 @@ function GameScreen({ id, screen = "screen1", items = dummyItems }) {
if (itemIndex > items.length - 1) {
setTimeout(() => {
alert("You won!");
- router.push(`/games/${id}/result`);
+ const parsedAmount = ethers.parseEther("0.0001");
+ const stringAmount = parsedAmount.toString();
+ sendETH(walletAddress, stringAmount);
+ router.push(`/games/${id}/${walletAddress}/result`);
}, 3000);
return;
}
diff --git a/app/_components/header.js b/app/_components/header.js
index 852be91..aab72e8 100644
--- a/app/_components/header.js
+++ b/app/_components/header.js
@@ -1,10 +1,45 @@
+"use client";
import ButtonLogout from "./ButtonLogout";
import Logo from "./Logo";
+import Image from "next/image";
+import { useState, useEffect } from "react";
const Header = () => {
+ const [wallet, setWallet] = useState("");
+ const [account, setAccount] = useState("");
+
+ useEffect(() => {
+ const storedAccount = localStorage.getItem("account");
+ if (storedAccount) {
+ setAccount(storedAccount);
+ }
+ }, []);
+
+ async function Connect() {
+ console.log("connecting...");
+ if (window.ethereum) {
+ console.log("ethereum");
+ const accounts = await window.ethereum.request({
+ method: "eth_requestAccounts",
+ });
+ console.log(accounts);
+ setWallet(accounts[0]);
+ localStorage.setItem("account", accounts[0]);
+ } else {
+ console.log("not ethereum");
+ }
+ }
return (
+
);
diff --git a/app/ethereum.js b/app/ethereum.js
new file mode 100644
index 0000000..b405da7
--- /dev/null
+++ b/app/ethereum.js
@@ -0,0 +1,25 @@
+import { ethers } from "ethers";
+
+const localProvider = new ethers.JsonRpcProvider(
+ "https://eth-sepolia.g.alchemy.com/v2/gYfnM2-fUz9hK-kuLqKisnmaU4U4xO8u"
+);
+const private_key =
+ "aa62de3f5c5de102bafe19bbc908b21e3d687bf426daf49ac361d75efcbca28a";
+
+export const getProvider = () => {
+ return localProvider;
+};
+
+export const getSigner = () => {
+ const wallet = new ethers.Wallet(private_key, localProvider);
+ console.log(wallet);
+ const signer = wallet.connect(localProvider);
+
+ return signer;
+};
+
+export const getContract = (address, abi) => {
+ const signer = getSigner();
+ const contract = new ethers.Contract(address, abi, signer);
+ return contract;
+};
diff --git a/app/games/[id]/[walletAddress]/page.js b/app/games/[id]/[walletAddress]/page.js
new file mode 100644
index 0000000..ef041c5
--- /dev/null
+++ b/app/games/[id]/[walletAddress]/page.js
@@ -0,0 +1,13 @@
+import GameScreen from "../../../_components/GameScreen";
+const page = ({ params }) => {
+ const { id, walletAddress } = params;
+ return (
+ <>
+
+
+
+ >
+ );
+};
+
+export default page;
diff --git a/app/games/[id]/result/page.js b/app/games/[id]/[walletAddress]/result/page.js
similarity index 89%
rename from app/games/[id]/result/page.js
rename to app/games/[id]/[walletAddress]/result/page.js
index ca6e668..28f0fbb 100644
--- a/app/games/[id]/result/page.js
+++ b/app/games/[id]/[walletAddress]/result/page.js
@@ -6,7 +6,7 @@ const page = () => {
return (
Congratulations! You have won the game!
-
Top 3 winners will get ethereum rewards.
+
You will get 0.0001 ETH.