forked from thirdweb-example/full-stack-web3-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (40 loc) · 1.2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { useContract, useContractRead, Web3Button } from "@thirdweb-dev/react";
import { useState } from "react";
// Your smart contract address here
const contractAddress = "0xB08BD1aa7Ee2291c60CE7FfcA4A070Fe2c5936F5";
export default function Home() {
// Get the smart contract
const { contract } = useContract(
"0xB08BD1aa7Ee2291c60CE7FfcA4A070Fe2c5936F5"
);
// Read the current greeting
const { data: currentGreeting, isLoading } = useContractRead(
contract,
"greet"
);
// Store the new greeting the user enters in the input in state
const [newGreeting, setNewGreeting] = useState("");
return (
<div>
{/* Display current greeting */}
<p>
Current greeting: <b>{isLoading ? "Loading..." : currentGreeting}</b>
</p>
{/* Add a new greeting */}
<input
type="text"
value={newGreeting}
className="input"
onChange={(e) => setNewGreeting(e.target.value)}
/>
<Web3Button
contractAddress={contractAddress}
action={(contract) => contract.call("setGreeting", newGreeting)}
colorMode="light"
accentColor="#F213A4"
>
Set Greeting
</Web3Button>
</div>
);
}