Skip to content

SDK API reference ​

Find StashWalletClient methods by function. Calls, parameters, and results are separated; longer type definitions are expandable.

Conventions

All request methods return promises and reject on failure. Result types describe the SDK contract, not guaranteed wallet support. Runtime capabilities, wallet validation, and user approval apply.

Client creation ​

For web integrations, use StashWalletClient.connect() to create a client. It waits for the wallet extension to inject its provider into the page, avoiding initialization failures when the page loads before the provider is ready.

ts
import { StashWalletClient } from 'stash-wallet-sdk'

const client = await StashWalletClient.connect()

Parameters and return value

  • timeoutMs: optional provider wait timeout in milliseconds, default 5000. When supplied, it also sets the timeout for subsequent wallet requests.
  • Returns Promise<StashWalletClient>. Once resolved, use the client to call wallet methods.

Creating a client does not request site authorization. To connect the user's wallet, call connect() on the client instance:

ts
const account = await client.connect()
console.log(account.address)

If the wallet extension cannot be detected, client creation fails with PROVIDER_NOT_FOUND. Prompt the user to install or enable the Stash Wallet extension, then reload the page and try again.

Create a client with the constructor ​

If the wallet provider is already available on the page, you can create a client directly:

ts
const client = new StashWalletClient()

The constructor does not wait for provider injection. The SDK checks for the page provider first, then tries Chrome extension communication. If neither is available, it throws PROVIDER_NOT_FOUND.

To customize communication, pass a Transport instance using the optional transport parameter. See Provider and events for configuration examples.

Check whether the extension is detected ​

isInstalled() reports whether the SDK detects a wallet provider or extension marker. Use it to control installation hints on the page.

ts
const detected = client.isInstalled()

Returns a boolean. A value of true only means the extension is detected, not that the wallet is unlocked or the user has authorized the site. This method requires an existing client instance. For initial setup, use StashWalletClient.connect() as shown above and handle creation failures.

Connection and accounts ​

connect ​

Request user approval for site access.

ts
client.connect()
// Promise<ConnectResult>

Result

ts
interface ConnectResult {
  address: string
}

disconnect ​

Revoke the current origin's authorization without locking the entire wallet.

ts
client.disconnect()
// Promise<boolean>

getAccounts ​

Returns an object, not an account array.

ts
client.getAccounts()
// Promise<AccountsResult>

Result

ts
interface AccountsResult {
  address: string
  btc_pub: string
  rgb_pub: string
}

getBtcAddress ​

ts
client.getBtcAddress()
// Promise<BtcAddressResponse>

Result

ts
interface BtcAddressResponse {
  address: string
  network: Network
}

Session, network, and capabilities ​

getWalletSessionStatus ​

ts
client.getWalletSessionStatus()
// Promise<WalletSessionStatus>

Result

ts
interface WalletSessionStatus {
  status: 'locked' | 'unlocked' | 'not_configured'
  network: Network | null
}

getNetwork ​

ts
client.getNetwork()
// Promise<{ network: Network }>

Network type

ts
type Network = 'mainnet' | 'testnet' | 'testnet4' | 'regtest'

Query supportedNetworks for actual support rather than relying on the type alone.

switchNetwork ​

May require approval or waiting for the switch. Refresh state and capabilities afterward.

ts
client.switchNetwork(network)
// Promise<{ network: Network; switched: boolean }>

Parameter: network is the target Network.

getVersion ​

ts
client.getVersion()
// Promise<{ version: string }>

getCapabilities ​

Query current runtime capabilities.

ts
client.getCapabilities()
// Promise<ProviderCapabilities>
Result type: ProviderCapabilities
ts
interface ProviderCapabilities {
  protocolVersion: string
  providerVersion: string
  canConnect: boolean
  canIssue: boolean
  canClaim: boolean
  canSwap: boolean
  canLsp: boolean
  canLspRevoke: boolean
  canAuthSign: boolean
  authNetworks: Network[]
  supportedNetworks: Network[]
}

Identity and message signing ​

requestAuthSignature ​

ts
client.requestAuthSignature(params)
// Promise<AuthSignatureResponse>

Parameter: AuthSignatureRequest, explicitly specifying version 1 or 2. See Auth login for full requests, responses, and verification.

signMessage ​

General message signing, not a substitute for the Auth challenge protocol.

ts
client.signMessage(params)
// Promise<SignMessageResult>

Parameters and result

ts
interface SignMessageRequest {
  message: string
  origin?: string
}

interface SignMessageResult {
  pubkey: string
  sign: string
}

Origin validation

The origin parameter cannot impersonate another site. The extension determines the actual origin from browser sender metadata.

RGB asset queries ​

getRgbUtxos ​

ts
client.getRgbUtxos()
// Promise<RgbUtxoItem[]>
Result type: RgbUtxoItem
ts
interface RgbUtxoItem {
  outpoint: string
  reserved: boolean
  value_sats?: string
  confirmed_height?: number
  assets?: {
    contract_id: string
    amount: string
  }[]
}

getContractBalance ​

ts
client.getContractBalance(contract_id)
// Promise<ContractBalanceResult>

Parameter: contract_id is a contract ID string.

Result

ts
interface ContractBalanceResult {
  contract_id: string
  confirmed: string
  unconfirmed: string
}

Amount precision

Do not convert amount strings into potentially imprecise JavaScript numbers. Apply asset precision when displaying values.

isContractKnown ​

ts
client.isContractKnown(contract_id)
// Promise<ContractKnownResult>

Parameter: contract_id is a contract ID string.

Result

ts
interface ContractKnownResult {
  contract_id: string
  known: boolean
}

Contract import and issuance ​

importContract ​

ts
client.importContract(params)
// Promise<{ contract_id: string }>

Parameters

ts
interface ImportContractRequest {
  contract_id: string
  consignment_key?: string
  origin?: string
}

autoImportContract ​

ts
client.autoImportContract(contract_id)
// Promise<{ contract_id: string; source: string; public_url?: string }>

Parameter: contract_id is a contract ID string.

issueContract ​

ts
client.issueContract(params)
// Promise<{ id: string }>

Parameters

ts
interface IssueContractRequest {
  ticker: string
  name: string
  supply: number
  precision: number
  seal?: string
  origin?: string
}

Supply and precision must pass wallet validation. Do not exceed the safe integer range. An exposed method does not guarantee issuance support.

Bitcoin, RGB, and Lightning payments ​

Fund operations

Page confirmation is not wallet authorization. Timeout does not cancel payment. Check authoritative transaction/payment status before retrying. Avoid logging credentials or unnecessary payment preimages.

sendBitcoin ​

ts
client.sendBitcoin(params)
// Promise<{ txid: string }>

Parameters

ts
interface SendBitcoinRequest {
  toAddress: string
  satoshis: number
  feeRate?: number
  origin?: string
}
  • satoshis: sat, not BTC.
  • feeRate: the SDK type does not specify a unit or default. Confirm against the target wallet version.

sendRGB ​

ts
client.sendRGB(params)
// Promise<{ payment_id: string; txid?: string }>

Parameters

ts
interface SendRGBRequest {
  invoice: string
  origin?: string
}

The presence of txid depends on the result.

payLightningInvoice ​

ts
client.payLightningInvoice(params)
// Promise<PayLightningInvoiceResponse>

Parameters

ts
interface PayLightningInvoiceRequest {
  invoice: string
  amount_msat?: string
  channel_id?: string
  fire_and_forget?: boolean
  require_rgb_channel?: boolean
}

Result

ts
interface PayLightningInvoiceResponse {
  payment_id: string
  preimage: string
  amount_sats: string
  destination: string
  fee_paid_msat?: string
}
  • amount_msat, fee_paid_msat: millisatoshi strings.
  • amount_sats: satoshi string.

The wallet validates invoice/payment rules. Page-supplied amounts are not authoritative quotes.

Sell invoices and native swaps ​

generateSellInvoice ​

ts
client.generateSellInvoice(params)
// Promise<{ invoice: string; payment_hash: string }>

Parameters

ts
interface GenerateSellInvoiceRequest {
  amount_sats: number
  description?: string
  expiry_secs?: number
  token_amount?: string
  token_ticker?: string
  fee_sats?: number
  total_revenue_sats?: number
}
  • amount_sats, fee_sats, total_revenue_sats: satoshis.
  • expiry_secs: seconds.

Trading services must obtain authoritative quotes and verify conditions independently. SDK parameters do not replace pricing, slippage checks, or settlement verification.

acceptNativeSwap ​

ts
client.acceptNativeSwap({ swap_string })
// Promise<void>

Parameter: swap_string is a swap string. An empty return value is not settlement proof.

Nodes and Hub channels ​

getNodeInfo ​

ts
client.getNodeInfo()
// Promise<NodeInfo>

Result

ts
interface NodeInfo {
  node_base_url: string
  node_id: string
  network: Network
  peer_address?: string
  stash_wallet_id?: string
}

getHubChannels ​

ts
client.getHubChannels(params?)
// Promise<HubChannelInfo[]>

Parameters

ts
interface HubChannelsRequest {
  hub_node_id?: string
  include_pending?: boolean
}
Result type: HubChannelInfo
ts
interface HubChannelInfo {
  channel_id: string
  user_channel_id?: string
  counterparty_node_id: string
  outbound_capacity_sats: number
  inbound_capacity_sats: number
  is_usable: boolean
  is_rgb: boolean
  rgb_contract_id?: string
}

Node credentials and grants ​

requestNodeCredential ​

Returns an encrypted package, not a plaintext token.

ts
client.requestNodeCredential(params)
// Promise<NodeCredentialResponse>

Parameters and result

ts
interface NodeCredentialRequest {
  recipient_pubkey: string
  expiry_seconds?: number
}

interface NodeCredentialResponse {
  encrypted_credential: string
  signature: string
  auth_pubkey: string
}

Obtain the recipient key from trusted service configuration. Do not expose credentials or packages in page logs.

requestNodeGrantSignature ​

The public grant type currently restricts the network to regtest.

ts
client.requestNodeGrantSignature(params)
// Promise<NodeGrantSignatureResponse>
Parameters: NodeGrantSignatureRequest
ts
interface NodeGrantSignatureRequest {
  node_id: string
  apis: string[]
  client_public_key: string
  expires_at: string
  api_risks?: Record<string, 'read' | 'write' | 'funds' | 'control'>
  rules?: Record<string, unknown>
  challenge: {
    challenge_id: string
    nonce: string
    timestamp: number
    expires_at: number
    wallet_type: 'stashwallet'
    network: 'regtest'
    origin: string
    purpose: 'grant'
    wallet_key: string
    user_id: string
  }
}

Result

ts
interface NodeGrantSignatureResponse {
  grant_signature: string
  grantor_public_key: string
  wallet_type: 'stashwallet'
  network: 'regtest'
  challenge_id: string
}

Top-level expires_at is a string; challenge timestamps are numbers. Do not interchange them. The authorization service must issue and validate challenges; page-generated values cannot establish trusted permissions.

LSP delegation ​

requestLspDelegation ​

Check canLsp first and handle runtime rejection.

ts
client.requestLspDelegation(params)
// Promise<LspDelegationResponse>

Parameters

ts
interface LspDelegationRequest {
  platform_pubkey?: string
  recipient_pubkey?: string
  platform?: string
  service_name?: string
  expiry_hours?: number
  registration?: LspDelegationRegistrationParams
}
  • platform_pubkey, platform: trusted platform key and display label.
  • recipient_pubkey, service_name: legacy aliases, filled from the corresponding new fields when missing. Do not provide conflicting values.
  • expiry_hours: hours.
Optional registration: LspDelegationRegistrationParams
ts
interface LspDelegationRegistrationParams {
  token_ticker?: string
  custom_fee_rate_percent?: number | string
  channel_hourly_fee_sats?: number
  p_ceiling?: number | string
  p_floor?: number | string
  swap_fee_lsp_percent?: number | string
  swap_fee_platform_percent?: number | string
  channel_fee_lsp_percent?: number | string
  channel_fee_platform_percent?: number | string
}

Result

ts
interface LspDelegationResponse {
  encrypted_package: string
  signature: string
  signer_pubkey: string
}

requestLspRevoke ​

ts
client.requestLspRevoke(platform)
// Promise<{ success: boolean }>

Parameter: platform is a platform name string.

Trade and secure your RGB assets | Unlock the full potential of the RGB protocol