request
The main method for interacting with Stacks and Bitcoin wallets via JSON-RPC. This method handles automatic error handling, request parameter serialization, wallet selection UI, and optional local storage caching.
For more advanced or low-level use cases, consider using the requestRaw method directly.
Usage
import { request } from '@stacks/connect';
// Simple usage with just a method and params
const result = await request('stx_transferStx', {
recipient: 'SP2...address',
amount: 1000000n,
memo: 'Payment',
});import { request } from '@stacks/connect';
// Usage with ConnectRequestOptions
const result = await request(
{
forceWalletSelect: true,
persistWalletSelect: true,
enableOverrides: true,
enableLocalStorage: true,
},
'stx_transferStx',
{
recipient: 'SP2...address',
amount: 1000000n,
memo: 'Payment',
}
);Notes
When no
provideris specified and no wallet has been previously selected, the wallet selection modal is automatically displayed.Parameters containing
bigintvalues and Clarity values are automatically serialized before being sent to the wallet.Post conditions are automatically serialized to hex strings.
If
enableLocalStorageistrue(the default), address results fromgetAddressescalls are cached in local storage.In SSR (server-side rendering) contexts, the method returns
undefinedinstead of throwing an error.Pressing
Escapewhile the wallet modal is open will cancel the request and throw aJsonRpcErrorwith codeUserCanceled.
Signature
The request function supports two call signatures via overloads:
Returns
Promise<MethodResult<M>>
The return type depends on the wallet method being called. Each wallet method defines its own result type. See individual method reference pages for specific return types.
getAddresses
sendTransfer
signPsbt
stx_transferStx
stx_callContract
stx_deployContract
stx_signTransaction
stx_signMessage
stx_signStructuredMessage
stx_getAddresses
stx_getAccounts
stx_updateProfile
stx_transferSip10Ft
stx_transferSip9Nft
Parameters
method (required)
Type:
keyof Methods
The wallet JSON-RPC method name to call. See the table above for all available methods.
params (optional)
Type:
MethodParams<M>
The parameters object for the specified method. Each method defines its own parameter type. See individual method reference pages for details.
options (optional)
Type:
ConnectRequestOptions
Configuration options for the request, including provider selection, wallet UI behavior, and local storage settings. See the ConnectRequestOptions reference for full details.
Error Handling
The request method throws a JsonRpcError when the wallet returns an error or the user cancels the request. You should wrap calls in a try/catch block:
Provider Override Behavior
When enableOverrides is true (the default), request automatically adjusts method names and parameter formats for different wallet providers (e.g. Xverse, Leather, Fordefi) to normalize behavior across the ecosystem. This includes:
Converting
getAddressestowallet_connectfor Xverse-like wallets.Normalizing
amounttypes betweennumberandstringdepending on the wallet.Transforming
signPsbtinput formats to match each wallet's expected schema.Normalizing response fields like
txIdvstxidandhexvspsbt.
Last updated
Was this helpful?