Class: Client

Client(baseURL, clientState)

The Starlight API Client object is the root object for all API interactions. To interact with Starlight, a Client object must always be instantiated first.

Constructor

new Client(baseURL, clientState)

Create a Client.
Parameters:
Name Type Description
baseURL string The URL of the Starlight agent.
clientState object The client state.
Source:

Methods

cancel(channelID) → {Promise.<ClientResponse.<string>>}

Cancel a proposed channel that your counterparty has not yet accepted.
Parameters:
Name Type Description
channelID string The channel ID.
Source:
Returns:
Type
Promise.<ClientResponse.<string>>

channelPay(channelID, amount) → {Promise.<ClientResponse.<string>>}

Make a payment over a channel.
Parameters:
Name Type Description
channelID string The channel ID.
amount number The amount (in stroops) to be paid.
Source:
Returns:
Type
Promise.<ClientResponse.<string>>

clearState()

Resets the client's state to an initial state.
Source:

close(channelID) → {Promise.<ClientResponse.<string>>}

Cooperatively close a channel.
Parameters:
Name Type Description
channelID string The channel ID.
Source:
Returns:
Type
Promise.<ClientResponse.<string>>

configEdit(params) → {Promise.<ClientResponse.<string>>}

Edit the instance's configuration.
Parameters:
Name Type Description
params object The configuration parameters.
Properties
Name Type Attributes Description
HorizonURL string <optional>
A new Horizon URL.
Password string <optional>
A new password.
OldPassword string <optional>
The old password, which must be provided if a new password is provided.
Source:
Returns:
Type
Promise.<ClientResponse.<string>>

(async) configInit(params) → {Promise.<ClientResponse.<Status>>}

Configure the instance with a username, password, and horizon URL.
Parameters:
Name Type Description
params object The configuration parameters.
Properties
Name Type Description
HorizonURL string The Horizon URL (by default, https://horizon-testnet.stellar.org).
Username string This will be the first part of your Stellar address (as in "alice*stellar.org").
Password string This will also be used to encrypt the instance's private key in storage.
Source:
Returns:
Type
Promise.<ClientResponse.<Status>>

createChannel(counterpartyAddress, initialDeposit) → {Promise.<ClientResponse.<string>>}

Attempt to open a channel with a specific counterparty.
Parameters:
Name Type Description
counterpartyAddress string The Stellar address of your counterparty (e.g., "alice*stellar.org").
initialDeposit number The amount (in stroops) you will initially deposit into the channel.
Source:
Returns:
Type
Promise.<ClientResponse.<string>>

deposit(channelID, amount) → {Promise.<ClientResponse.<string>>}

Add more money to a channel you created.
Parameters:
Name Type Description
channelID string The channel ID.
amount number The amount (in stroops) to be deposited.
Source:
Returns:
Type
Promise.<ClientResponse.<string>>

findAccount(address) → {Promise.<ClientResponse.<Status>>}

Find the account ID (e.g., "G...") corresponding to a Stellar address (e.g., "alice*stellar.org").
Parameters:
Name Type Description
address string
Source:
Returns:
accountID
Type
Promise.<ClientResponse.<Status>>

forceClose(channelID) → {Promise.<ClientResponse.<string>>}

Attempt to force close a channel.
Parameters:
Name Type Description
channelID string The channel ID.
Source:
Returns:
Type
Promise.<ClientResponse.<string>>

getStatus() → {Promise.<(Status|undefined)>}

Get the current status of the instance (whether the instance is configured, and if so, whether the user is logged in).
Source:
Returns:
Type
Promise.<(Status|undefined)>

login(username, password) → {Promise.<ClientResponse.<string>>}

Authenticate with a Starlight instance. This also decrypts the instance's private key, allowing it to sign transactions and accept channels.
Parameters:
Name Type Description
username string
password number
Source:
Returns:
Type
Promise.<ClientResponse.<string>>

logout(username, password) → {Promise.<ClientResponse.<string>>}

Log out of a Starlight instance.
Parameters:
Name Type Description
username string
password number
Source:
Returns:
Type
Promise.<ClientResponse.<string>>

setState(clientState)

Restore the client's state from a snapshot.
Parameters:
Name Type Description
clientState object The client state.
Source:

subscribe(updateHandler)

Subscribe to updates from the Starlight instance. The first time this is called, the handler will be called with all updates in the instance's history.
Parameters:
Name Type Description
updateHandler function A handler function that updates will be passed to.
Source:

unsubscribe()

Stop subscribing to updates from the Starlight instance.
Source:

walletPay(channelID, amount) → {Promise.<ClientResponse.<string>>}

Make a payment on the public network.
Parameters:
Name Type Description
channelID string The channel ID.
amount number The amount (in stroops) to be paid.
Source:
Returns:
Type
Promise.<ClientResponse.<string>>