Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 provider is specified and no wallet has been previously selected, the wallet selection modal is automatically displayed.

  • Parameters containing bigint values and Clarity values are automatically serialized before being sent to the wallet.

  • Post conditions are automatically serialized to hex strings.

  • If enableLocalStorage is true (the default), address results from getAddresses calls are cached in local storage.

  • In SSR (server-side rendering) contexts, the method returns undefined instead of throwing an error.

  • Pressing Escape while the wallet modal is open will cancel the request and throw a JsonRpcError with code UserCanceled.


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.

Method
Result Type

getAddresses

sendTransfer

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)

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 getAddresses to wallet_connect for Xverse-like wallets.

  • Normalizing amount types between number and string depending on the wallet.

  • Transforming signPsbt input formats to match each wallet's expected schema.

  • Normalizing response fields like txId vs txid and hex vs psbt.

Last updated

Was this helpful?