@@ -102,6 +102,7 @@ import { Wallet, generateMnemonic } from 'beignet';
102102import net from ' net'
103103import tls from ' tls'
104104import { TStorage } from ' ./wallet' ;
105+ import { ECoinSelectPreference } from " ./transaction" ;
105106
106107// Generate a mnemonic phrase
107108const mnemonic = generateMnemonic ();
@@ -111,10 +112,10 @@ const passphrase = 'passphrase';
111112
112113// Connect to custom electrum server
113114const 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 ,
118119};
119120
120121// Use a specific network (Defaults to mainnet)
@@ -128,43 +129,47 @@ const addressTypesToMonitor = [EAddressType.p2tr, EAddressType.p2wpkh];
128129
129130// Subscribe to server messages (TOnMessage)
130131const onMessage: TOnMessage = (id , data ) => {
131- console .log (id );
132- console .dir (data , { depth: null });
132+ console .log (id );
133+ console .dir (data , { depth: null });
133134}
134135
135136// Disable startup messages. Messages resume once startup is complete. (Defaults to false)
136137const disableMessagesOnCreate = true ;
137138
138139// Persist sessions by getting and setting data from storage
139140const 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+ }
151152};
152153
154+ // Set the auto coin selection preference. (Defaults to ECoinSelectPreference.consolidate)
155+ const coinSelectPreference = ECoinSelectPreference .small ;
156+
153157// Create a wallet instance
154158const 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
168173});
169174if (createWalletRes .isErr ()) return ;
170175const wallet = createWalletRes .value ;
@@ -174,18 +179,18 @@ const utxos = wallet.listUtxos();
174179
175180// Send sats to multiple outputs
176181const 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 },
180185];
181186const sendManyRes = await wallet .sendMany ({ txs });
182187
183188// Sweep from a private key
184189const 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
189194});
190195
191196// Get tx history for a given address. { tx_hash: string; height: number; }[]
0 commit comments