diff --git a/docs/build/tools/react-sdk/hooks.md b/docs/build/tools/react-sdk/hooks.md index 2ce8623497..64fb098409 100644 --- a/docs/build/tools/react-sdk/hooks.md +++ b/docs/build/tools/react-sdk/hooks.md @@ -24,7 +24,7 @@ Many of these hooks are built using [`@tanstack/react-query`](https://tanstack.c import { useFlowCurrentUser } from "@onflow/react-sdk" ``` -### Parameters +#### Parameters - `flowClient?: FlowClient` - Optional `FlowClient` instance @@ -447,6 +447,8 @@ function RandomValues() { Since the hook uses script executions on existing blocks, the random source is already public and the randoms are predictable. * For **more advanced use cases** that **do** require onchain randomness logic via transactions, Flow provides built-in support using Cadence's `revertibleRandom` and [commit-reveal scheme]. +[commit-reveal scheme]: ../../cadence/advanced-concepts/randomness#commit-reveal-scheme + --- ### `useFlowTransaction` @@ -551,6 +553,398 @@ function ThemeAwareComponent() { --- +### `useFlowNftMetadata` + + + +```tsx +import { useFlowNftMetadata } from "@onflow/react-sdk" +``` + +This hook fetches NFT metadata including display information, traits, rarity, and collection details. + +#### Parameters: + +- `accountAddress?: string` – Flow address of the account holding the NFT +- `tokenId?: string | number` – The NFT token ID +- `publicPathIdentifier?: string` – Public path identifier for the collection +- `query?: UseQueryOptions` – Optional TanStack Query options +- `flowClient?: FlowClient` - Optional `FlowClient` instance + +#### Returns: `UseQueryResult` + +Where `NftViewResult` is defined as: + +```typescript +interface NftViewResult { + name: string + description: string + thumbnailUrl: string + externalUrl?: string + collectionName?: string + collectionExternalUrl?: string + tokenID: string + traits?: Record + rarity?: string + serialNumber?: string +} +``` + +```tsx +function NftMetadataExample() { + const { data: nft, isLoading, error } = useFlowNftMetadata({ + accountAddress: "0x1cf0e2f2f715450", + tokenId: "123", + publicPathIdentifier: "exampleNFTCollection", + query: { staleTime: 60000 }, + }) + + if (isLoading) return

Loading NFT metadata...

+ if (error) return

Error: {error.message}

+ if (!nft) return

NFT not found

+ + return ( +
+

{nft.name}

+ {nft.name} +

{nft.description}

+ {nft.collectionName &&

Collection: {nft.collectionName}

} + {nft.rarity &&

Rarity: {nft.rarity}

} + {nft.traits && ( +
+

Traits:

+
    + {Object.entries(nft.traits).map(([key, value]) => ( +
  • {key}: {value}
  • + ))} +
+
+ )} +
+ ) +} +``` + +--- + +### `useFlowAuthz` + +```tsx +import { useFlowAuthz } from "@onflow/react-sdk" +``` + +A React hook that returns an authorization function for Flow transactions. If no custom authorization is provided, it returns the current user's wallet authorization. + +#### Parameters: + +- `authz?: AuthorizationFunction` – Optional custom authorization function +- `flowClient?: FlowClient` - Optional `FlowClient` instance + +Where `AuthorizationFunction` is defined as: + +```typescript +type AuthorizationFunction = ( + account: Partial +) => Partial | Promise> +``` + +#### Returns: `AuthorizationFunction` + +The authorization function is compatible with Flow transactions' authorizations parameter. + +```tsx +// Example 1: Using current user authorization +function CurrentUserAuthExample() { + const authorization = useFlowAuthz() + + const sendTransaction = async () => { + const txId = await fcl.mutate({ + cadence: ` + transaction { + prepare(signer: auth(Storage) &Account) { + log(signer.address) + } + } + `, + authorizations: [authorization], + limit: 100, + }) + console.log("Transaction ID:", txId) + } + + return +} +``` + +```tsx +// Example 2: Using custom authorization function +function CustomAuthExample() { + const customAuthz = (account) => ({ + ...account, + addr: "0xCUSTOMOADDRESS", + keyId: 0, + signingFunction: async (signable) => ({ + signature: "0x...", + }), + }) + + const authorization = useFlowAuthz({ authz: customAuthz }) + + const sendTransaction = async () => { + const txId = await fcl.mutate({ + cadence: ` + transaction { + prepare(signer: auth(Storage) &Account) { + log(signer.address) + } + } + `, + authorizations: [authorization], + limit: 100, + }) + console.log("Transaction ID:", txId) + } + + return +} +``` + +--- + +### `useFlowScheduledTransaction` + + + +```tsx +import { useFlowScheduledTransaction } from "@onflow/react-sdk" +``` + +Fetches a scheduled transaction by ID. + +#### Parameters: + +- `txId?: string` – Scheduled transaction ID +- `includeHandlerData?: boolean` – Include handler data (default: false) +- `query?: UseQueryOptions` – Optional TanStack Query options +- `flowClient?: FlowClient` - Optional `FlowClient` instance + +#### Returns: `UseQueryResult` + +Where `ScheduledTransaction` is defined as: + +```typescript +interface ScheduledTransaction { + id: string + priority: ScheduledTransactionPriority // 0 = Low, 1 = Medium, 2 = High + executionEffort: bigint + status: ScheduledTransactionStatus // 0 = Pending, 1 = Processing, 2 = Completed, 3 = Failed, 4 = Cancelled + fees: { + value: bigint + formatted: string + } + scheduledTimestamp: number + handlerTypeIdentifier: string + handlerAddress: string + handlerUUID?: string // Only included if includeHandlerData is true + handlerResolvedViews?: {[viewType: string]: any} // Only included if includeHandlerData is true +} +``` + +```tsx +function ScheduledTransactionDetails({ txId }: { txId: string }) { + const { data: transaction, isLoading, error } = useFlowScheduledTransaction({ + txId, + query: { staleTime: 10000 }, + }) + + if (isLoading) return

Loading scheduled transaction...

+ if (error) return

Error: {error.message}

+ if (!transaction) return

Transaction not found

+ + return ( +
+

Scheduled Transaction #{transaction.id}

+

Status: {transaction.status}

+

Priority: {transaction.priority}

+

Fees: {transaction.fees.formatted} FLOW

+

Handler: {transaction.handlerTypeIdentifier}

+
+ ) +} +``` + +--- + +### `useFlowScheduledTransactionList` + + + +```tsx +import { useFlowScheduledTransactionList } from "@onflow/react-sdk" +``` + +Lists all scheduled transactions for an account. + +#### Parameters: + +- `account?: string` – Flow address to query +- `includeHandlerData?: boolean` – Include handler data (default: false) +- `query?: UseQueryOptions` – Optional TanStack Query options +- `flowClient?: FlowClient` - Optional `FlowClient` instance + +#### Returns: `UseQueryResult` + +```tsx +function ScheduledTransactionsList({ account }: { account: string }) { + const { data: transactions, isLoading, error, refetch } = useFlowScheduledTransactionList({ + account, + query: { staleTime: 10000 }, + }) + + if (isLoading) return

Loading scheduled transactions...

+ if (error) return

Error: {error.message}

+ if (!transactions || transactions.length === 0) return

No scheduled transactions

+ + return ( +
+

Scheduled Transactions for {account}

+ +
    + {transactions.map((tx) => ( +
  • + Transaction #{tx.id} - Status: {tx.status} - Fees: {tx.fees.formatted} FLOW +
  • + ))} +
+
+ ) +} +``` + +--- + +### `useFlowScheduledTransactionCancel` + + + +```tsx +import { useFlowScheduledTransactionCancel } from "@onflow/react-sdk" +``` + +Cancels a scheduled transaction and refunds fees. + +#### Parameters: + +- `mutation?: UseMutationOptions` – Optional TanStack Query mutation options +- `flowClient?: FlowClient` - Optional `FlowClient` instance + +#### Returns: `UseFlowScheduledTransactionCancelResult` + +Where `UseFlowScheduledTransactionCancelResult` is defined as: + +```typescript +interface UseFlowScheduledTransactionCancelResult extends Omit< + UseMutationResult, + "mutate" | "mutateAsync" +> { + cancelTransaction: (txId: string) => void + cancelTransactionAsync: (txId: string) => Promise +} +``` + +```tsx +function CancelScheduledTransaction() { + const { cancelTransactionAsync, isPending, error, data: txId } = useFlowScheduledTransactionCancel({ + mutation: { + onSuccess: (txId) => console.log("Cancel transaction ID:", txId), + }, + }) + + const handleCancel = async (scheduledTxId: string) => { + try { + const resultTxId = await cancelTransactionAsync(scheduledTxId) + console.log("Successfully canceled scheduled transaction:", resultTxId) + } catch (error) { + console.error("Failed to cancel:", error) + } + } + + return ( +
+ + {isPending &&

Canceling transaction...

} + {error &&

Error: {error.message}

} + {txId &&

Cancel Transaction ID: {txId}

} +
+ ) +} +``` + +--- + +### `useFlowScheduledTransactionSetup` + + + +```tsx +import { useFlowScheduledTransactionSetup } from "@onflow/react-sdk" +``` + +Sets up the Transaction Scheduler Manager resource. + +#### Parameters: + +- `mutation?: UseMutationOptions` – Optional TanStack Query mutation options +- `flowClient?: FlowClient` - Optional `FlowClient` instance + +#### Returns: `UseFlowScheduledTransactionSetupResult` + +Where `UseFlowScheduledTransactionSetupResult` is defined as: + +```typescript +interface UseFlowScheduledTransactionSetupResult extends Omit< + UseMutationResult, + "mutate" | "mutateAsync" +> { + setup: () => void + setupAsync: () => Promise +} +``` + +```tsx +function SchedulerSetup() { + const { setupAsync, isPending, error, data: txId } = useFlowScheduledTransactionSetup({ + mutation: { + onSuccess: (txId) => console.log("Setup transaction ID:", txId), + }, + }) + + const handleSetup = async () => { + try { + const resultTxId = await setupAsync() + console.log("Scheduler setup successful:", resultTxId) + } catch (error) { + console.error("Setup failed:", error) + } + } + + return ( +
+ + {isPending &&

Setting up scheduler...

} + {error &&

Error: {error.message}

} + {txId &&

Setup Transaction ID: {txId}

} +
+ ) +} +``` + +--- + ## Cross-VM Hooks ### `useCrossVmBatchTransaction` @@ -669,6 +1063,7 @@ Fetch the balance of a token balance for a given user across both Cadence and EV - `flowClient?: FlowClient` - Optional `FlowClient` instance > **Note:** You must pass `owner`, and one of `vaultIdentifier` or `erc20AddressHexArg`. + #### Returns: `UseQueryResult` Where `UseCrossVmTokenBalanceData` is defined as: @@ -716,72 +1111,133 @@ function UseCrossVmTokenBalanceExample() { --- -### `useCrossVmSpendNft` +### `useCrossVmTransactionStatus` - + ```tsx -import { useCrossVmSpendNft } from "@onflow/react-sdk" +import { useCrossVmTransactionStatus } from "@onflow/react-sdk" ``` -Bridge NFTs from Cadence to Flow EVM and execute arbitrary EVM transactions to atomically spend them. +Subscribes to status updates for a given Cross-VM Flow transaction ID that executes EVM calls. This hook monitors the transaction status and extracts EVM call results if available. #### Parameters: -- `mutation?: UseMutationOptions` – Optional TanStackQuery mutation options +- `id?: string` – Optional Flow transaction ID to monitor - `flowClient?: FlowClient` - Optional `FlowClient` instance -Where `UseCrossVmSpendFtMutateArgs` is defined as: +#### Returns: `UseCrossVmTransactionStatusResult` + +Where `UseCrossVmTransactionStatusResult` is defined as: ```typescript -interface UseCrossVmSpendFtMutateArgs { - nftIdentifier: string // Cadence NFT identifier (e.g. "0x1cf0e2f2f715450.FlowNFT") - nftIds: string[] // Array of NFT IDs to bridge - calls: EVMBatchCall[] // Array of EVM calls to execute atomically +interface UseCrossVmTransactionStatusResult { + transactionStatus: TransactionStatus | null // Latest transaction status, or null before any update + evmResults?: CallOutcome[] // EVM transaction results, if available + error: Error | null // Any error encountered during status updates +} +``` + +Where `CallOutcome` is defined as: + +```typescript +interface CallOutcome { + status: "passed" | "failed" | "skipped" // Status of the EVM call + hash?: string // EVM transaction hash if available + errorMessage?: string // Error message if the call failed +} +``` + +```tsx +function CrossVmTransactionStatusComponent() { + const txId = "your-cross-vm-transaction-id-here" + const { transactionStatus, evmResults, error } = useCrossVmTransactionStatus({ id: txId }) + + if (error) return
Error: {error.message}
+ + return ( +
+
Flow Status: {transactionStatus?.statusString}
+ {evmResults && evmResults.length > 0 && ( +
+

EVM Call Results:

+
    + {evmResults.map((result, idx) => ( +
  • + Status: {result.status} + {result.hash && | Hash: {result.hash}} + {result.errorMessage && | Error: {result.errorMessage}} +
  • + ))} +
+
+ )} +
+ ) } ``` -#### Returns: `UseCrossVmSpendNftResult` +--- + +### `useCrossVmBridgeNftFromEvm` + + + +```tsx +import { useCrossVmBridgeNftFromEvm } from "@onflow/react-sdk" +``` + +This hook bridges NFTs from Flow EVM to Cadence. It withdraws an NFT from the signer's COA (Cadence Owned Account) in EVM and deposits it into their Cadence collection. -Where `UseCrossVmSpendNftResult` is defined as: +#### Parameters: + +- `mutation?: UseMutationOptions` – Optional TanStackQuery mutation options +- `flowClient?: FlowClient` - Optional `FlowClient` instance + +#### Returns: `UseCrossVmBridgeNftFromEvmTxResult` + +Where `UseCrossVmBridgeNftFromEvmTxResult` is defined as: ```typescript -interface UseCrossVmSpendNftResult extends Omit< - UseMutationResult, +interface UseCrossVmBridgeNftFromEvmTxResult extends Omit< + UseMutationResult, "mutate" | "mutateAsync" > { - spendNft: (params: CrossVmSpendNftParams) => Promise - spendNftAsync: (params: CrossVmSpendNftParams) => Promise + crossVmBridgeNftFromEvm: (args: UseCrossVmBridgeNftFromEvmTxMutateArgs) => void + crossVmBridgeNftFromEvmAsync: (args: UseCrossVmBridgeNftFromEvmTxMutateArgs) => Promise +} +``` + +Where `UseCrossVmBridgeNftFromEvmTxMutateArgs` is defined as: + +```typescript +interface UseCrossVmBridgeNftFromEvmTxMutateArgs { + nftIdentifier: string // Cadence type identifier (e.g., "A.0x123.MyNFT.NFT") + nftId: string // EVM NFT ID as string representation of UInt256 } ``` ```tsx -function CrossVmSpendNftExample() { - const { spendNft, isPending, error, data: txId } = useCrossVmSpendNft() +function BridgeNftFromEvmExample() { + const { crossVmBridgeNftFromEvm, isPending, error, data: txId } = useCrossVmBridgeNftFromEvm({ + mutation: { + onSuccess: (txId) => console.log("Transaction ID:", txId), + }, + }) - const handleSpendNft = () => { - spendNft({ - nftIdentifier: "0x1cf0e2f2f715450.FlowNFT", // Cadence NFT identifier - nftIds: ["1"], // Array of NFT IDs to bridge - calls: [ - { - abi: contractAbi, // ABI of the EVM contract - contractAddress: "0x1234567890abcdef1234567890abcdef12345678", // EVM contract address - functionName: "transferNFT", - args: ["123"], // Example args - value: "1000000000000000000", // Amount in wei (if applicable) - gasLimit: "21000", // Gas limit for the EVM call - }, - ], + const handleBridge = () => { + crossVmBridgeNftFromEvm({ + nftIdentifier: "A.0x1cf0e2f2f715450.ExampleNFT.NFT", + nftId: "123", }) } return (
- - {isPending &&

Sending transaction...

} + {isPending &&

Bridging NFT...

} {error &&

Error: {error.message}

} {txId &&

Transaction ID: {txId}

}
@@ -791,61 +1247,64 @@ function CrossVmSpendNftExample() { --- -### `useCrossVmSpendToken` +### `useCrossVmBridgeNftToEvm` - + ```tsx -import { useCrossVmSpendToken } from "@onflow/react-sdk" +import { useCrossVmBridgeNftToEvm } from "@onflow/react-sdk" ``` -Bridge FTs from Cadence to Flow EVM and execute arbitrary EVM transactions to atomically spend them. +This hook bridges NFTs from Cadence to Flow EVM and executes arbitrary EVM transactions atomically. It withdraws NFTs from the signer's Cadence collection and deposits them into their COA in EVM, then executes the provided EVM calls. #### Parameters: -- `mutation?: UseMutationOptions` – Optional TanStackQuery mutation options +- `mutation?: UseMutationOptions` – Optional TanStackQuery mutation options - `flowClient?: FlowClient` - Optional `FlowClient` instance -Where `UseCrossVmSpendTokenMutateArgs` is defined as: +#### Returns: `UseCrossVmBridgeNftToEvmTxResult` + +Where `UseCrossVmBridgeNftToEvmTxResult` is defined as: ```typescript -interface UseCrossVmSpendTokenMutateArgs { - vaultIdentifier: string; // Cadence vault identifier (e.g. "0x1cf0e2f2f715450.ExampleToken.Vault") - amount: string; // Amount of tokens to bridge, as a decimal string (e.g. "1.23") - calls: EVMBatchCall[]; // Array of EVM calls to execute after bridging +interface UseCrossVmBridgeNftToEvmTxResult extends Omit< + UseMutationResult, + "mutate" | "mutateAsync" +> { + crossVmBridgeNftToEvm: (args: UseCrossVmBridgeNftToEvmTxMutateArgs) => void + crossVmBridgeNftToEvmAsync: (args: UseCrossVmBridgeNftToEvmTxMutateArgs) => Promise } ``` -#### Returns: `UseCrossVmSpendTokenResult` - -Where `UseCrossVmSpendTokenResult` is defined as: +Where `UseCrossVmBridgeNftToEvmTxMutateArgs` is defined as: ```typescript -interface UseCrossVmSpendTokenResult extends Omit< - UseMutationResult, - "mutate" | "mutateAsync" -> { - spendToken: (args: UseCrossVmSpendTokenMutateArgs) => void; // Function to trigger the FT bridging and EVM calls - spendTokenAsync: (args: UseCrossVmSpendTokenMutateArgs) => Promise; // Async version of spendToken +interface UseCrossVmBridgeNftToEvmTxMutateArgs { + nftIdentifier: string // Cadence NFT type identifier + nftIds: string[] // Array of NFT IDs to bridge + calls: EvmBatchCall[] // Array of EVM calls to execute after bridging } ``` ```tsx -function CrossVmSpendTokenExample() { - const { spendToken, isPending, error, data: txId } = useCrossVmSpendToken() +function BridgeNftToEvmExample() { + const { crossVmBridgeNftToEvm, isPending, error, data: txId } = useCrossVmBridgeNftToEvm({ + mutation: { + onSuccess: (txId) => console.log("Transaction ID:", txId), + }, + }) - const handleSpendToken = () => { - spendToken({ - vaultIdentifier: "0x1cf0e2f2f715450.ExampleToken.Vault", // Cadence vault identifier - amount: "1.23", // Amount of tokens to bridge to EVM + const handleBridge = () => { + crossVmBridgeNftToEvm({ + nftIdentifier: "A.0x1cf0e2f2f715450.ExampleNFT.NFT", + nftIds: ["1", "2", "3"], calls: [ { - abi: myEvmContractAbi, // EVM contract ABI - address: "0x01234567890abcdef01234567890abcdef", // EVM contract address - function: "transfer", // EVM function to call - args: [ - "0xabcdef01234567890abcdef01234567890abcdef", // Recipient address - ], + address: "0x1234567890abcdef1234567890abcdef12345678", + abi: myContractAbi, + functionName: "transferNFT", + args: ["0xRecipient", 1n], + gasLimit: 100000n, }, ], }) @@ -853,12 +1312,12 @@ function CrossVmSpendTokenExample() { return (
- - {isPending &&

Sending transaction...

} + {isPending &&

Bridging NFTs...

} {error &&

Error: {error.message}

} - {txId &&

Cadence Transaction ID: {txId}

} + {txId &&

Transaction ID: {txId}

}
) } @@ -866,70 +1325,146 @@ function CrossVmSpendTokenExample() { --- -### `useCrossVmTransactionStatus` +### `useCrossVmBridgeTokenFromEvm` - + ```tsx -import { useCrossVmTransactionStatus } from "@onflow/react-sdk" +import { useCrossVmBridgeTokenFromEvm } from "@onflow/react-sdk" ``` -Subscribes to status updates for a given Cross-VM Flow transaction ID that executes EVM calls. This hook monitors the transaction status and extracts EVM call results if available. +This hook bridges fungible tokens from Flow EVM to Cadence. It withdraws tokens from the signer's COA in EVM and deposits them into their Cadence vault. #### Parameters: -- `id?: string` – Optional Flow transaction ID to monitor +- `mutation?: UseMutationOptions` – Optional TanStackQuery mutation options - `flowClient?: FlowClient` - Optional `FlowClient` instance -#### Returns: `UseCrossVmTransactionStatusResult` +#### Returns: `UseCrossVmBridgeTokenFromEvmResult` -Where `UseCrossVmTransactionStatusResult` is defined as: +Where `UseCrossVmBridgeTokenFromEvmResult` is defined as: ```typescript -interface UseCrossVmTransactionStatusResult { - transactionStatus: TransactionStatus | null // Latest transaction status, or null before any update - evmResults?: CallOutcome[] // EVM transaction results, if available - error: Error | null // Any error encountered during status updates +interface UseCrossVmBridgeTokenFromEvmResult extends Omit< + UseMutationResult, + "mutate" | "mutateAsync" +> { + crossVmBridgeTokenFromEvm: (args: UseCrossVmBridgeTokenFromEvmMutateArgs) => void + crossVmBridgeTokenFromEvmAsync: (args: UseCrossVmBridgeTokenFromEvmMutateArgs) => Promise } ``` -Where `CallOutcome` is defined as: +Where `UseCrossVmBridgeTokenFromEvmMutateArgs` is defined as: ```typescript -interface CallOutcome { - status: "passed" | "failed" | "skipped" // Status of the EVM call - hash?: string // EVM transaction hash if available - errorMessage?: string // Error message if the call failed +interface UseCrossVmBridgeTokenFromEvmMutateArgs { + vaultIdentifier: string // Cadence vault type identifier (e.g., "A.0x123.FlowToken.Vault") + amount: string // Amount as UInt256 string representation } ``` ```tsx -function CrossVmTransactionStatusComponent() { - const txId = "your-cross-vm-transaction-id-here" - const { transactionStatus, evmResults, error } = useCrossVmTransactionStatus({ id: txId }) +function BridgeTokenFromEvmExample() { + const { crossVmBridgeTokenFromEvm, isPending, error, data: txId } = useCrossVmBridgeTokenFromEvm({ + mutation: { + onSuccess: (txId) => console.log("Transaction ID:", txId), + }, + }) - if (error) return
Error: {error.message}
+ const handleBridge = () => { + crossVmBridgeTokenFromEvm({ + vaultIdentifier: "A.0x1654653399040a61.FlowToken.Vault", + amount: "1000000000", // Amount in smallest unit + }) + } return (
-
Flow Status: {transactionStatus?.statusString}
- {evmResults && evmResults.length > 0 && ( -
-

EVM Call Results:

-
    - {evmResults.map((result, idx) => ( -
  • - Status: {result.status} - {result.hash && | Hash: {result.hash}} - {result.errorMessage && | Error: {result.errorMessage}} -
  • - ))} -
-
- )} + + {isPending &&

Bridging tokens...

} + {error &&

Error: {error.message}

} + {txId &&

Transaction ID: {txId}

}
) } ``` -[commit-reveal scheme]: ../../cadence/advanced-concepts/randomness#commit-reveal-scheme \ No newline at end of file +--- + +### `useCrossVmBridgeTokenToEvm` + + + +```tsx +import { useCrossVmBridgeTokenToEvm } from "@onflow/react-sdk" +``` + +This hook bridges fungible tokens from Cadence to Flow EVM and executes arbitrary EVM transactions atomically. It withdraws tokens from the signer's Cadence vault and deposits them into their COA in EVM, then executes the provided EVM calls. + +#### Parameters: + +- `mutation?: UseMutationOptions` – Optional TanStackQuery mutation options +- `flowClient?: FlowClient` - Optional `FlowClient` instance + +#### Returns: `UseCrossVmBridgeTokenToEvmResult` + +Where `UseCrossVmBridgeTokenToEvmResult` is defined as: + +```typescript +interface UseCrossVmBridgeTokenToEvmResult extends Omit< + UseMutationResult, + "mutate" | "mutateAsync" +> { + crossVmBridgeTokenToEvm: (args: UseCrossVmBridgeTokenToEvmMutateArgs) => void + crossVmBridgeTokenToEvmAsync: (args: UseCrossVmBridgeTokenToEvmMutateArgs) => Promise +} +``` + +Where `UseCrossVmBridgeTokenToEvmMutateArgs` is defined as: + +```typescript +interface UseCrossVmBridgeTokenToEvmMutateArgs { + vaultIdentifier: string // Cadence vault type identifier + amount: string // Amount as decimal string (e.g., "1.5") + calls: EvmBatchCall[] // Array of EVM calls to execute after bridging +} +``` + +```tsx +function BridgeTokenToEvmExample() { + const { crossVmBridgeTokenToEvm, isPending, error, data: txId } = useCrossVmBridgeTokenToEvm({ + mutation: { + onSuccess: (txId) => console.log("Transaction ID:", txId), + }, + }) + + const handleBridge = () => { + crossVmBridgeTokenToEvm({ + vaultIdentifier: "A.0x1654653399040a61.FlowToken.Vault", + amount: "10.5", + calls: [ + { + address: "0x1234567890abcdef1234567890abcdef12345678", + abi: erc20Abi, + functionName: "transfer", + args: ["0xRecipient", 1000000n], + gasLimit: 100000n, + }, + ], + }) + } + + return ( +
+ + {isPending &&

Bridging tokens...

} + {error &&

Error: {error.message}

} + {txId &&

Transaction ID: {txId}

} +
+ ) +} +``` diff --git a/src/components/ReactSDKOverview.tsx b/src/components/ReactSDKOverview.tsx index 0cbb01b482..b3df219994 100644 --- a/src/components/ReactSDKOverview.tsx +++ b/src/components/ReactSDKOverview.tsx @@ -629,10 +629,113 @@ function UseFlowRevertibleRandomCardMini({ darkMode }: { darkMode: boolean }) { ); } +// Starter Banner Component +function StarterBanner({ darkMode }: { darkMode: boolean }) { + return ( +
+
+
+
+

+ Looking for a starter? +

+

+ Try our Next.js starter template with Flow React SDK + pre-configured and ready to be used. +

+
+ + + View Starter + + + + +
+
+
+ ); +} + // Inner component with all the cards function ReactSDKOverviewContent({ darkMode }: { darkMode: boolean }) { return (
+ +