useSimulateTransaction
Hook for simulating a transaction on the Aptos network without broadcasting it. Accepts either a raw transaction or payload data and returns a detailed simulation result including gas estimates and events.
Usage
import { useSimulateTransaction } from "@aptos-labs/react";
import { AccountAddress } from "@aptos-labs/ts-sdk";
export default function App() {
const { data: simulation, isLoading } = useSimulateTransaction({
data: {
function: "0x1::aptos_account::transfer",
functionArguments: [
AccountAddress.from(
"0x926ff619e85bdb5b02680f27bea5ea3302c71f86be4b16fa0d63df213add927a",
),
100,
],
},
});
if (isLoading) {
return <div>Simulating transaction...</div>;
}
return (
<div>
<h1>Simulation Result</h1>
<pre>{JSON.stringify(simulation, null, 2)}</pre>
</div>
);
}
Parameters
Return Type
Name | Type | Default |
---|---|---|
data | UserTransactionResponse | undefined The last successfully resolved data for the query. The last successfully resolved data for the query. The last successfully resolved data for the query. The last successfully resolved data for the query. The last successfully resolved data for the query. The last successfully resolved data for the query. | |
error | Error | null The error object for the query, if an error was thrown.
| |
isError | boolean A derived boolean from the
| |
isPending | boolean Will be | |
isLoading | boolean Is
| |
isLoadingError | boolean Will be | |
isRefetchError | boolean Will be | |
isSuccess | boolean A derived boolean from the
| |
isPlaceholderData | boolean Will be | |
status | "error" | "success" | "pending" The status of the query.
| |
dataUpdatedAt | number The timestamp for when the query most recently returned the | |
errorUpdatedAt | number The timestamp for when the query most recently returned the | |
failureCount | number The failure count for the query.
| |
failureReason | Error | null The failure reason for the query retry.
| |
errorUpdateCount | number The sum of all errors. | |
isFetched | boolean Will be | |
isFetchedAfterMount | boolean Will be
| |
isFetching | boolean A derived boolean from the
| |
isInitialLoading | boolean | |
isPaused | boolean A derived boolean from the
| |
isRefetching | boolean Is
| |
isStale | boolean Will be | |
refetch | (options?: RefetchOptions | undefined) => Promise<QueryObserverResult<UserTransactionResponse, Error>> A function to manually refetch the query. | |
fetchStatus | FetchStatus The fetch status of the query.
| |
promise | Promise<UserTransactionResponse> A stable promise that will be resolved with the data of the query.
Requires the |