beignet 0.0.51 → 0.0.53

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
@@ -102,6 +102,7 @@ import { Wallet, generateMnemonic } from 'beignet';
102
102
  import net from 'net'
103
103
  import tls from 'tls'
104
104
  import { TStorage } from './wallet';
105
+ import { ECoinSelectPreference } from "./transaction";
105
106
 
106
107
  // Generate a mnemonic phrase
107
108
  const mnemonic = generateMnemonic();
@@ -111,10 +112,10 @@ const passphrase = 'passphrase';
111
112
 
112
113
  // Connect to custom electrum server
113
114
  const servers: TServer = {
114
- host: '35.233.47.252',
115
- ssl: 18484,
116
- tcp: 18483,
117
- protocol: EProtocol.ssl,
115
+ host: '35.233.47.252',
116
+ ssl: 18484,
117
+ tcp: 18483,
118
+ protocol: EProtocol.ssl,
118
119
  };
119
120
 
120
121
  // Use a specific network (Defaults to mainnet)
@@ -128,8 +129,8 @@ const addressTypesToMonitor = [EAddressType.p2tr, EAddressType.p2wpkh];
128
129
 
129
130
  // Subscribe to server messages (TOnMessage)
130
131
  const onMessage: TOnMessage = (id, data) => {
131
- console.log(id);
132
- console.dir(data, { depth: null });
132
+ console.log(id);
133
+ console.dir(data, { depth: null });
133
134
  }
134
135
 
135
136
  // Disable startup messages. Messages resume once startup is complete. (Defaults to false)
@@ -137,34 +138,38 @@ const disableMessagesOnCreate = true;
137
138
 
138
139
  // Persist sessions by getting and setting data from storage
139
140
  const storage: TStorage = {
140
- async getData<K extends keyof IWalletData>(
141
- key: string
142
- ): Promise<Result<IWalletData[K]>> {
143
- // Add your logic here
144
- },
145
- async setData<K extends keyof IWalletData>(
146
- key: string,
147
- value: IWalletData[K]
148
- ): Promise<Result<boolean>> {
149
- // Add your logic here
150
- }
141
+ async getData<K extends keyof IWalletData>(
142
+ key: string
143
+ ): Promise<Result<IWalletData[K]>> {
144
+ // Add your logic here
145
+ },
146
+ async setData<K extends keyof IWalletData>(
147
+ key: string,
148
+ value: IWalletData[K]
149
+ ): Promise<Result<boolean>> {
150
+ // Add your logic here
151
+ }
151
152
  };
152
153
 
154
+ // Set the auto coin selection preference. (Defaults to ECoinSelectPreference.consolidate)
155
+ const coinSelectPreference = ECoinSelectPreference.small;
156
+
153
157
  // Create a wallet instance
154
158
  const createWalletRes = await Wallet.create({
155
- mnemonic,
156
- passphrase,
157
- electrumOptions: {
158
- servers,
159
- net,
160
- tls
161
- },
162
- network,
163
- onMessage,
164
- storage,
165
- addressType,
166
- addressTypesToMonitor,
167
- disableMessagesOnCreate
159
+ mnemonic,
160
+ passphrase,
161
+ electrumOptions: {
162
+ servers,
163
+ net,
164
+ tls
165
+ },
166
+ network,
167
+ onMessage,
168
+ storage,
169
+ addressType,
170
+ addressTypesToMonitor,
171
+ disableMessagesOnCreate,
172
+ coinSelectPreference
168
173
  });
169
174
  if (createWalletRes.isErr()) return;
170
175
  const wallet = createWalletRes.value;
@@ -174,18 +179,18 @@ const utxos = wallet.listUtxos();
174
179
 
175
180
  // Send sats to multiple outputs
176
181
  const txs = [
177
- { address: 'address1', amount: 1000 },
178
- { address: 'address2', amount: 2000 },
179
- { address: 'address3', amount: 3000 },
182
+ { address: 'address1', amount: 1000 },
183
+ { address: 'address2', amount: 2000 },
184
+ { address: 'address3', amount: 3000 },
180
185
  ];
181
186
  const sendManyRes = await wallet.sendMany({ txs });
182
187
 
183
188
  // Sweep from a private key
184
189
  const sweepPrivateKeyRes = await wallet.sweepPrivateKey({
185
- privateKey: 'privateKey',
186
- toAddress: 'toAddress',
187
- satsPerByte: 5,
188
- broadcast: false
190
+ privateKey: 'privateKey',
191
+ toAddress: 'toAddress',
192
+ satsPerByte: 5,
193
+ broadcast: false
189
194
  });
190
195
 
191
196
  // Get tx history for a given address. { tx_hash: string; height: number; }[]