Skip to main content

useExecuteContract

Mutation hook to executing transactions against a CosmWasm smart contract. Note: senderAddress will be filled with current connected account.

Usage

import { useExecuteContract, useCosmWasmSigningClient } from "graz";

interface TData {
// ...
}

const contractAddress = "cosmosfoobarbaz";
const { data: signingClient } = useCosmWasmSigningClient();
const { executeContract } = useExecuteContract<TData>({ contractAddress });

executeContract({
signingClient,
msg: {
foo: "bar",
},
});

Types

  • ExecuteContractMutationArgs
    {
    signingClient?: SigningCosmWasmClient;
    msg: Record<string, unknown>;
    fee?: StdFee | "auto" | number; // will be default to "auto"
    }

Params

Object params

  • onError?: (error: unknown, args: ExecuteResult) => void
  • onMutate?: (data: ExecuteResult) => void
  • onSuccess?: (data: ExecuteResult) => void

Note: ExecuteResult is from @cosmjs/cosmwasm-stargate

Return Value

{
error: unknown;
isLoading: boolean;
isSuccess: boolean;
executeContract: (args: ExecuteContractMutationArgs) => void;
executeContractAsync: (args: ExecuteContractMutationArgs) => Promise<ExecuteResult>;
status: "error" | "idle" | "loading" | "success";
}