Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update wagmi, viem and rainbowkit versions #626

Merged
merged 2 commits into from
Nov 27, 2023
Merged

Conversation

technophile-04
Copy link
Collaborator

@technophile-04 technophile-04 commented Nov 27, 2023

Description

Nicely tested the whole app and everything works great 🙌

Here is the test Index.ts page file :

Test file with main hooks and imperative read/write examples :
import { useEffect } from "react";
import Link from "next/link";
import type { NextPage } from "next";
import { parseEther } from "viem";
import { useAccount, useWalletClient } from "wagmi";
import { BugAntIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline";
import { MetaHeader } from "~~/components/MetaHeader";
import { Address } from "~~/components/scaffold-eth";
import {
  useScaffoldContract,
  useScaffoldContractRead,
  useScaffoldContractWrite,
  useScaffoldEventHistory,
} from "~~/hooks/scaffold-eth";

const Home: NextPage = () => {
  const { address: connectedAddress } = useAccount();
  const { writeAsync: writeSetGreetings } = useScaffoldContractWrite({
    contractName: "YourContract",
    functionName: "setGreeting",
    args: ["Hello World!"],
    value: parseEther("0.01"),
  });

  const { data: totalCounter } = useScaffoldContractRead({
    contractName: "YourContract",
    functionName: "totalCounter",
    watch: true,
  });

  const { data: walletClient } = useWalletClient();

  const { data: YourContract } = useScaffoldContract({
    contractName: "YourContract",
    walletClient,
  });

  useEffect(() => {
    const fetchTotalCounter = async () => {
      const value = await YourContract?.read.totalCounter();
      console.log("totalCounter", value);
    };

    fetchTotalCounter();
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);

  const { data: eventHistory } = useScaffoldEventHistory({
    contractName: "YourContract",
    eventName: "GreetingChange",
    filters: { greetingSetter: connectedAddress },
    fromBlock: 0n,
    watch: true,
  });

  console.log("eventHistory", eventHistory);

  return (
    <>
      <MetaHeader />
      <div className="flex items-center flex-col flex-grow pt-10">
        <div className="text-center mb-8">
          <span className="block text-2xl mb-2">The connected address is</span>
          <Address address={connectedAddress} />
        </div>
        <div className="px-5">
          <h1 className="text-center mb-4">
            <span className="block text-3xl mb-2">With Hooks</span>
          </h1>
          <h1 className="text-center mb-4">
            <span className="block text-2xl mb-2">The totalCounter is</span>
            <span className="block text-4xl font-bold">{totalCounter?.toString()}</span>
          </h1>
          <button className="btn btn-primary btn-sm ml-12 mb-2" onClick={() => writeSetGreetings()}>
            Send Transaction
          </button>
          <h1 className="text-center mt-8">
            <span className="block text-3xl mb-2">Imperative</span>
          </h1>
          <button
            className="btn btn-primary btn-sm"
            onClick={async () => {
              await YourContract?.write.setGreeting(["hello world"], { value: parseEther("0.01") });
            }}
          >
            Send Imperative Transaction
          </button>
        </div>
      </div>
    </>
  );
};

export default Home;

Also, I think its kind of good if we stay up-to-date with viem, Wagmi, and Rainbowkit maybe we do it every month's end (which we are kind of following already)🙌

Here is prod url : https://wagmi-viem-rainbowkit.vercel.app/

@technophile-04
Copy link
Collaborator Author

This also closes #418, since Viem has added pgn init and also added pgn to hardhat.config.ts at 7199bf6

@carletex
Copy link
Member

Thank you @technophile-04 Everything works great.

Super helpful that you put the code to test the hooks in the PR. I'll save it for future updates :)

Also, I think its kind of good if we stay up-to-date with viem, Wagmi, and Rainbowkit maybe we do it every month's end (which we are kind of following already)🙌

💯

@carletex carletex merged commit b2a91b8 into main Nov 27, 2023
1 check passed
@carletex carletex deleted the up-viem-wagmi-rainbow branch November 27, 2023 11:18
This was referenced Nov 28, 2023
@github-actions github-actions bot mentioned this pull request Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants