@xo-cash/engine 0.0.1 → 0.1.0-next.17295903694

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,34 +13,37 @@ npm install @xo-cash/engine
13
13
  ### Basic Setup
14
14
 
15
15
  ```typescript
16
- import { Engine } from '@xo-cash/engine';
17
- import { createElectrumClient } from '@electrum-cash/network';
18
-
19
- // Create an Electrum client for blockchain connectivity
20
- const client = await createElectrumClient({
21
- // client configuration
22
- });
23
-
24
- // Initialize the engine with wallet seed and storage options
25
- const engine = await Engine.create('your-wallet-seed', client, {
16
+ import { Engine, XO_SUPPORTED_NETWORKS } from '@xo-cash/engine';
17
+ import { StorageType } from '@xo-cash/state';
18
+ import { p2pkhTemplate } from '@xo-cash/templates';
19
+
20
+ // Create the engine for one account. It connects to the Electrum servers of the network itself.
21
+ const engine = await Engine.create('your BIP39 mnemonic', {
22
+ network: XO_SUPPORTED_NETWORKS.chipnet,
23
+ storageType: StorageType.SQLITE,
26
24
  databasePath: './',
27
25
  databaseFilename: 'XO',
28
- defaultTemplateHubUrl: 'https://template-hub.example.com',
29
26
  });
30
27
 
31
- // Import a template
32
- const templateIdentifier = await engine.importTemplate(templateJson);
28
+ // Import a template. The result carries the template and its identifier.
29
+ const { templateIdentifier } = await engine.importTemplate(p2pkhTemplate);
33
30
 
34
- // List available starting actions for a template
35
- const startingActions = await engine.listStartingActions(templateIdentifier);
31
+ // Read the actions the template can start with.
32
+ const startingActions = (await engine.getTemplate(templateIdentifier))?.start ?? [];
36
33
 
37
- // Create an invitation for a specific action
38
- const invitation = await engine.createInvitation({
34
+ // Create an invitation for one of those actions.
35
+ const storedInvitation = await engine.createInvitation({
39
36
  templateIdentifier,
40
- actionIdentifier: 'action-id',
37
+ actionIdentifier: 'requestSatoshis',
38
+ intent: startingActions.find((startingAction) => startingAction.action === 'requestSatoshis'),
41
39
  });
40
+
41
+ // Stop the engine to close its Electrum connections and storage, and destroy its keys.
42
+ await engine.stop();
42
43
  ```
43
44
 
45
+ See `playground/examples/receive-satoshis.js` for a full flow that funds, signs, and executes an invitation.
46
+
44
47
  ## Links
45
48
 
46
49
  - [Repository](https://gitlab.com/GeneralProtocols/xo/engine)