@spicenet-io/spiceflow-ui@5.0.3, connect your existing selector, amount input and button to
useSpiceSupply. It is the same controller used by the stock SpiceSupply component.
Your app defines the destination contract calls and renders the returned state. The SDK owns asset
inventory, route selection, fee estimates, Max, funding, signing and transaction completion.
Provider Setup
Mount the provider stack once above this panel. Reuse your existing Privy, wagmi and Query providers. Setnetwork="mainnet" explicitly for production;
the default remains "testnet". SDK styles load automatically in the browser.
Complete Example
This panel deposits USDC into an ERC-4626 vault on Base. Pass the address of your vault, whoseasset() must be Base USDC. For another protocol, replace only the destination token and the
buildActionCalls body with that protocol’s ABI and calls.
destinationToken,
selectedAsset, and buildActionCalls. Only chainId and address are required for the destination
token; symbol and decimals resolve from SDK metadata or the chain. Your selected asset and amount
are UI state, while the vault address and its calls remain your protocol’s configuration.
enabled defaults to true. For a modal that stays mounted while hidden, pass enabled: isOpen.
Keep it true while fees load and use canExecute for button readiness. The default amount direction
for this selected-asset example is "input".
Amount Semantics
For Pay, use this same hook with
amountDirection: "output" and paymentAmount. There is no
separate useSpicePay hook. Use flow.submit() for the configured direction, render
flow.fees.preview with its own symbol/decimals, and enable the action only when flow.canExecute.
max() returns a fee-aware source amount string or null; never replace null with the full balance.
buildActionCalls receives a raw bigint in destination-token units, including the protected
minimum when routing requires a swap. Use that argument, not the source input text, to encode approvals
and protocol calls. The builder can run during planning; it must not send transactions or write
application state. Put post-transaction updates in an awaited onSuccess callback.
Wallets, Beneficiaries and Sources
Keep the selectedAsset object intact. Key rows with assetPositionId(asset) and show wallet/location
alongside token and chain: the same token can exist in multiple wallets or in Spice balance.
Funding can come from either connected wallet by default, even when account mode chooses a different
position owner. Use sourceChains, supportedSourceAssets, includeExternalWalletAssets, or
includeCrossChainEmbeddedAssets only when your product needs a restriction.
For a fixed protocol beneficiary, pass recipient and use ctx.beneficiary ?? ctx.userAddress
in the action calls. ctx.executorAddress identifies the executing wallet; it can differ from the
beneficiary. External mode with its matching destination token on the same chain executes directly
through the SDK. By default, routed external sources fund the embedded execution wallet. A contract that credits
only msg.sender cannot automatically credit a different beneficiary; constrain that action to a
compatible source/executor rather than changing the recipient silently.
Completion and Errors
Render controller loading, fee, readiness and status fields directly. Keep balances visible duringassets.refreshing; reserve the initial loader for assets.loading. onSubmit() is an optional
notification after the SDK accepts a submission and before wallet prompts, not an execution override.
Await app work in onSuccess, such as refreshing a position or recording access. If that work fails,
retryFinalization() retries the application update without resending the confirmed transaction.
Accepted actions can continue on the backend when the configured API supports automatic continuation.
Render status.pending, status.recoveryChecking and status.recoveryError, and offer
refreshStatus() to check the original action. Closing the form or losing a response is not cancellation.
The SDK does not persist a browser action journal; after a reload, do not assume your app’s previous
success callback will replay. Refresh application state from authoritative records.
For a captured routed external-wallet action, render status.canRetry and call the same submit()
to resume the accepted action. Do not rebuild its funding or destination calls. refreshStatus() and
retrySupply() only read status. After consuming a confirmed successful result, call
resetAfterSuccess() to prepare a new action.
Supply/Pay reports the verified destination transaction hash; backend settlement may still continue.
Use that destination result for your app update, rather than treating a funding transfer as completion.
See Recovery and completion.
For an app-owned pre-submit check, pass beforeSubmit(review). The SDK awaits it and revalidates the
operation before sending. Throw to reject the submission; use submitDisabled for host readiness.
onSubmit is a notification and is not awaited for asynchronous validation.
For an account Cash purchase without a single selected token, see Cash funding.
Fee-Only Actions and Withdrawals
For a protocol action whose principal already sits in the executing wallet, usefeeOnlyAction.
Declare consumed tokens through actionInput and, if applicable, resulting funds through
actionProceeds. The SDK chooses fee funding in input, proceeds, balance order by default;
feeFunding can restrict that order. The builder must honor the amount it receives after any fee
allocation. These are optional declarations for this action type, not requirements for ordinary Supply.
For funded wallet actions on the destination chain, actionProceeds: "output" or an explicit nonempty
feeFunding list opts into that hierarchy. Fixed input/output principal is reserved; input-inclusive
budgets may pay fees. feeFundingReserve can identify principal unavailable for fees. Within a fee
source tier, direct payment precedes conversion. Keep the returned fee quote authoritative; do not
rebuild fee transfers in the host. Cross-chain and rollup principal routes retain their earlier funding
requirements.
SpiceWithdraw withdraws Spice balance, not a lending position. Protocol withdrawals use your
protocol’s own calls with the controller. SpiceDeposit and SpiceWithdraw retain their separate
callback contracts; do not migrate their callbacks as if they were Pay or Lock.
See Hooks for the controller reference and Migration to 5.0.0
for the changes from manual integration.