Skip to content

Commit

Permalink
writeContract from client
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Jun 5, 2024
1 parent 5eff5e3 commit d00e90d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions templates/react/packages/client/src/mud/createSystemCalls.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Hex } from "viem";
import { writeContract } from "viem/actions";
import { SetupNetworkResult } from "./setupNetwork";
import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
import { AppAccountClient } from "@latticexyz/account-kit";
Expand All @@ -8,7 +7,7 @@ export type SystemCalls = ReturnType<typeof createSystemCalls>;

export function createSystemCalls({ tables, useStore, waitForTransaction, worldAddress }: SetupNetworkResult) {
const addTask = async (client: AppAccountClient, label: string) => {
const tx = await writeContract(client, {
const tx = await client.writeContract({
address: worldAddress,
abi: IWorldAbi,
functionName: "app__addTask",
Expand All @@ -20,13 +19,13 @@ export function createSystemCalls({ tables, useStore, waitForTransaction, worldA
const toggleTask = async (client: AppAccountClient, id: Hex) => {
const isComplete = (useStore.getState().getValue(tables.Tasks, { id })?.completedAt ?? 0n) > 0n;
const tx = isComplete
? await writeContract(client, {
? await client.writeContract({
address: worldAddress,
abi: IWorldAbi,
functionName: "app__resetTask",
args: [id],
})
: await writeContract(client, {
: await client.writeContract({
address: worldAddress,
abi: IWorldAbi,
functionName: "app__completeTask",
Expand All @@ -36,7 +35,7 @@ export function createSystemCalls({ tables, useStore, waitForTransaction, worldA
};

const deleteTask = async (client: AppAccountClient, id: Hex) => {
const tx = await writeContract(client, {
const tx = await client.writeContract({
address: worldAddress,
abi: IWorldAbi,
functionName: "app__deleteTask",
Expand Down

0 comments on commit d00e90d

Please sign in to comment.