sensei-client-js
A javascript client for the Sensei HTTP API. This is designed to work in the browser and in NodeJS environments. There are typescript types available for all endpoints.
Installation
Can be added to your project by running npm install --save @l2-technology/sensei-client
Authentication
When using from the browser you can rely on login
and logout
to set a cookie with a macaroon
that will automatically be passed for future requests.
When using from nodeJS you can use setMacaroon
to explicitly set a macaroon to use for the client instance.
Usage
Instantiate and export a client to use from a utils/integration file
import SenseiClient from '@l2-technology/sensei-client';
const senseiHost = 'http://localhost:3000';
const senseiClient = new SenseiClient({ basePath: senseiHost });
export default senseiClient;
Import your client and use it
import senseiClient from './src/utils/sensei';
const { pubkey, macaroon } = await senseiClient.init({
username: 'satoshi',
alias: 'satoshi',
passphrase: 'donthardcodethissomewhere',
electrumUrl: 'ssl://blockstream.info:993',
start: true,
});
senseiClient.setMacaroon(macaroon);
const { address } = await senseiClient.getUnusedAddress();
const { alicePubkey, aliceMacaroon } = await senseiClient.createNode({
username: 'alice',
alias: 'alice',
passphrase: 'alicespassphrase',
start: true,
});
const { nodes } = await senseiClient.getNodes({
page: 0,
searchTerm: alicePubkey,
take: 1,
});
const aliceNodeInfo = nodes[0];
const { listenAddr, listenPort } = aliceNodeInfo;
await senseiClient.openChannel({
nodeConnectionString: `${alicePubkey}@${listenAddr}:${listenPort}`,
amtSatoshis: 25000,
isPublic: true,
});
senseiClient.setMacaroon(aliceMacaroon);
const { invoice } = await senseiClient.createInvoice({
amountMillisats: 1000000,
description: 'paying for some coffee',
});
senseiClient.setMacaroon(macaroon);
await senseiClient.payInvoice(invoice);