@stacks/connect
The @stacks/connect package provides a simple interface for connecting web applications to Stacks wallets, enabling user authentication, transaction signing, and message signing capabilities.
Installation
npm install @stacks/connectConnection functions
connect
connect initiates a wallet connection and stores user addresses in local storage.
Signature:
function connect(options?: ConnectOptions): Promise<ConnectResponse>Parameters
options
ConnectOptions
No
Configuration options for connection
Examples
Basic connection
import { connect } from '@stacks/connect';
const response = await connect();
// Response contains user addresses stored in local storageConnection with options
isConnected
isConnected checks if a wallet is currently connected.
disconnect
disconnect clears the connection state and local storage.
getLocalStorage
getLocalStorage retrieves stored connection data.
Request method
request
request is the primary method for interacting with connected wallets.
Signature:
Parameters
options
RequestOptions
No
Request configuration options
method
StacksMethod
Yes
Method to call on the wallet
params
MethodParams[T]
Depends on method
Parameters for the method
Request options
provider
StacksProvider
Auto-detect
Custom provider instance
forceWalletSelect
boolean
false
Force wallet selection modal
persistWalletSelect
boolean
true
Persist wallet selection
enableOverrides
boolean
true
Enable compatibility fixes
enableLocalStorage
boolean
true
Store addresses locally
approvedProviderIds
string[]
All providers
Filter available wallets
Examples
Basic request
Request with options
Wallet methods
getAddresses
getAddresses retrieves Bitcoin and Stacks addresses from the wallet.
sendTransfer
sendTransfer sends Bitcoin to one or more recipients.
signPsbt
signPsbt signs a partially signed Bitcoin transaction.
Stacks-specific methods
stx_transferStx
stx_transferStx transfers STX tokens between addresses.
stx_callContract
stx_callContract calls a public function on a smart contract.
stx_deployContract
stx_deployContract deploys a new smart contract.
stx_signMessage
stx_signMessage signs a plain text message.
stx_signStructuredMessage
stx_signStructuredMessage signs a structured Clarity message following SIP-018.
stx_getAccounts
stx_getAccounts retrieves detailed account information including Gaia configuration.
Error handling
Handle wallet errors using standard Promise error handling patterns.
Advanced usage
requestRaw
requestRaw provides direct access to wallet providers without compatibility features.
Signature:
Example
Migration notes
Version 8.x.x implements SIP-030 wallet standards. For legacy JWT-based authentication, use version 7.10.1.
Was this helpful?
