Skip to content
Starknet Start

useSendTransaction

Hook to send one or several transaction(s) to the network.

Use this hook together with useContract to send transactions to the network in a type-safe way.

Usage

The following example shows how to transfer $STRK tokens to an address.

import { , , ,  } from "@starknetfoundation/starknet-start-react";
import type {  } from "starknet";
 
const  = [
  {
    : "function",
    : "transfer",
    : "external",
    : [
      {
        : "recipient",
        : "core::starknet::contract_address::ContractAddress",
      },
      {
        : "amount",
        : "core::integer::u256",
      },
    ],
    : [],
  },
] as  satisfies ;
 
const {  } = ();
const {  } = ();
 
const {  } = ({
  , 
  : .., 
}); 
 
const { ,  } = ({
  :
     &&  
      ? [.("transfer", [, 1n])] 
      : , 
}); 

Arguments

calls

  • Type: (Call | WalletApiCall)[]

List of smart contract calls to execute. Accepts Starknet.js Call objects and wallet API calls returned by wallet_strk20PrepareInvoke.

proof

  • Type: STRK20_PROOF | undefined

Optional proof returned by wallet_strk20PrepareInvoke. Pass this when submitting a STRK20 prepared call yourself.

Returns

send

  • Type: (args?: (Call | WalletApiCall)[] | { calls?: (Call | WalletApiCall)[]; proof?: STRK20_PROOF }) => void

Function to send the request to the user, optionally overriding the arguments to the hook.

sendAsync

  • Type: (args?: (Call | WalletApiCall)[] | { calls?: (Call | WalletApiCall)[]; proof?: STRK20_PROOF }) => Promise<AddInvokeTransactionResult>

Send the request to the user and block until it receives a response.

data

  • Type: AddInvokeTransactionResult | undefined

The resolved data. This type is defined in the Starknet Types package.

error

  • Type: Error | null

Any error thrown by the mutation.

reset

  • Type: () => void

Reset the mutation status.

variables

  • Type: RequestArgs<"wallet_addInvokeTransaction"> | undefined

The request variables used by the underlying wallet mutation.

status

  • Type: "error" | "idle" | "pending" | "success"

The mutation status.

  • idle: the mutation has not been triggered yet.
  • pending: the mutation is being executed, e.g. waiting for the user to confirm in their wallet.
  • success: the mutation executed without an error.
  • error: the mutation threw an error.

isError

  • Type: boolean

Derived from status.

isIdle

  • Type: boolean

Derived from status.

isPending

  • Type: boolean

Derived from status.

isSuccess

  • Type: boolean

Derived from status.