Created
May 8, 2025 09:06
-
-
Save technophile-04/440c3844aa9f8163b38fa10b313356b6 to your computer and use it in GitHub Desktop.
Revisions
-
technophile-04 revised this gist
May 8, 2025 . No changes.There are no files selected for viewing
-
technophile-04 created this gist
May 8, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ "use client"; import type { NextPage } from "next"; import { erc20Abi } from "viem"; import { useAccount, useWriteContract } from "wagmi"; import { useTransactor } from "~~/hooks/scaffold-eth"; const ERC20_ABI = erc20Abi; const Home: NextPage = () => { const { address: connectedAddress } = useAccount(); // Dynamic address const dynmaicAddress = "0x0000000000000000000000000000000000000000"; // Using wagmi write hook const { writeContractAsync } = useWriteContract(); // Using scaffold-eth transactor hook const writeTx = useTransactor(); const handleButtonClick = async () => { // First we create a function that will be used to write to the contract (passing args to wagmi's write hoook) const makeWriteWithParams = () => writeContractAsync({ abi: ERC20_ABI, address: dynmaicAddress, functionName: "transfer", args: [connectedAddress || "", 100n], }); // Then we use the transactor hook to send the transaction await writeTx(makeWriteWithParams); }; return ( <> <button onClick={handleButtonClick}>Click me</button> </> ); }; export default Home;