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 {
useSendTransaction,
useContract,
useNetwork,
useAccount,
} from "@starknet-react/core";
import type { Abi } from "starknet";
const abi = [
{
type: "function",
name: "transfer",
state_mutability: "external",
inputs: [
{
name: "recipient",
type: "core::starknet::contract_address::ContractAddress",
},
{
name: "amount",
type: "core::integer::u256",
},
],
outputs: [],
},
] as const satisfies Abi;
const { address } = useAccount();
const { chain } = useNetwork();
const { contract } = useContract({
abi,
address: chain.nativeCurrency.address,
});
const { send, error } = useSendTransaction({
calls:
contract && address
? [contract.populate("transfer", [address, 1n])]
: undefined,
});
Arguments
calls
- Type:
Call[]
List of smart contract calls to execute. Type is from starknet
Returns
send
- Type:
(args?: Call[]) => void
Function to send the request to the user, optionally overriding the arguments to the hook.
sendAsync
- Type:
(args?: Call[]) => 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:
Call[] | undefined
The variables passed to send
or sendAsync
.
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
.