LightsparkSyncWalletClient

Main entry point for the Lightspark SDK which makes synchronous, blocking API calls.

This client should only be used in environments where asynchronous calls are not possible, or where you explicitly want to block the current thread or control the concurrency yourself. Prefer using the LightsparkCoroutinesWalletClient or LightsparkFuturesWalletClient where possible.

// Initialize the client with oauth:
val oAuthHelper = OauthHelper(applicationContext)
val lightsparkClient = LightsparkSyncWalletClient(ClientConfig(
authProvider = OAuthProvider(oAuthHelper)
))

// An example API call fetching the dashboard info for the active account:
val dashboard = lightsparkClient.getWalletDashboard()

or in java:

// Initialize the client with oauth:
OAuthHelper oAuthHelper = new OAuthHelper(applicationContext);
LightsparkSyncWalletClient lightsparkClient = new LightsparkSyncWalletClient(new ClientConfig(
authProvider = new OAuthProvider(oAuthHelper)
));

// An example API call fetching the dashboard info for the active account:
WalletDashboard dashboard = lightsparkClient.getWalletDashboard();

Note: This client object keeps a local cache in-memory, so a single instance should be reused throughout the lifetime of your app.

Constructors

Link copied to clipboard
constructor(config: ClientConfig)

Functions

Link copied to clipboard

Creates an L1 Bitcoin wallet address which can be used to deposit or withdraw funds from the Lightning wallet.

Link copied to clipboard
fun createInvoice(amountMsats: Long, memo: String? = null, type: InvoiceType = InvoiceType.STANDARD): InvoiceData

Creates a lightning invoice for the current wallet.

Link copied to clipboard
fun decodeInvoice(encodedInvoice: String): InvoiceData

Decode a lightning invoice to get its details included payment amount, destination, etc.

Link copied to clipboard

Deploys a wallet in the Lightspark infrastructure. This is an asynchronous operation, the caller should then poll the wallet frequently (or subscribe to its modifications). When this process is over, the Wallet status will change to DEPLOYED (or FAILED).

Link copied to clipboard
fun <T> executeQuery(query: Query<T>): T

Executes a raw graphql query against the server.

Link copied to clipboard

Get the L1 fee estimate for a deposit or withdrawal.

Link copied to clipboard
Link copied to clipboard
suspend fun getLightningFeeEstimateForInvoice(encodedPaymentRequest: String, amountMsats: Long? = null): CurrencyAmount

Gets an estimate of the fees that will be paid for a Lightning invoice.

Link copied to clipboard
suspend fun getLightningFeeEstimateForNode(destinationNodePublicKey: String, amountMsats: Long): CurrencyAmount

Returns an estimate of the fees that will be paid to send a payment to another Lightning node.

Link copied to clipboard
fun getWalletDashboard(numTransactions: Int = 20, numPaymentRequests: Int = 20): WalletDashboard?

Get the dashboard overview for a Lightning wallet. Includes balance info and the most recent transactions and payment requests.

Link copied to clipboard
fun initializeWallet(keyType: KeyType, signingPublicKey: String): Wallet

Initializes a wallet in the Lightspark infrastructure and syncs it to the Bitcoin network. This is an asynchronous operation, the caller should then poll the wallet frequently (or subscribe to its modifications). When this process is over, the Wallet status will change to READY (or FAILED).

Link copied to clipboard
Link copied to clipboard
fun loadWalletSigningKey(signingKeyBytesPEM: ByteArray)

Unlocks the wallet for use with the SDK for the current application session. This function must be called before any other functions that require wallet signing keys, including payInvoice.

Link copied to clipboard
fun loginWithJWT(accountId: String, jwt: String, storage: JwtStorage): LoginWithJWTOutput

Login using the Custom JWT authentication scheme described in our documentation.

Link copied to clipboard
fun payInvoice(encodedInvoice: String, maxFeesMsats: Long, amountMsats: Long? = null, timeoutSecs: Int = 60): OutgoingPayment

Pay a lightning invoice from the current wallet.

Link copied to clipboard
fun requestWithdrawal(amountSats: Long, bitcoinAddress: String): WithdrawalRequest

Withdraws funds from the account and sends it to the requested bitcoin address.

Link copied to clipboard
fun sendPayment(destinationPublicKey: String, amountMsats: Long, maxFeesMsats: Long, timeoutSecs: Int = 60): OutgoingPayment

Sends a payment directly to a node on the Lightning Network through the public key of the node without an invoice.

Link copied to clipboard
fun setAuthProvider(authProvider: AuthProvider)

Override the auth token provider for this client to provide custom headers on all API calls.

Link copied to clipboard

Removes the wallet from Lightspark infrastructure. It won't be connected to the Lightning network anymore and its funds won't be accessible outside of the Funds Recovery Kit process.