# ToBTCLNWrapper\<T>

Defined in: [atomiq-sdk/src/swaps/escrow\_swaps/tobtc/ln/ToBTCLNWrapper.ts:93](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts#L93)

Escrow based (HTLC) swap for Smart chains -> Bitcoin lightning

## Extends

* [`IToBTCWrapper`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md)<`T`, `ToBTCLNDefinition`<`T`>, `ToBTCLNWrapperOptions`>

## Type Parameters

| Type Parameter                                                                                                       |
| -------------------------------------------------------------------------------------------------------------------- |
| `T` *extends* [`ChainType`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/ChainType.md) |

## Constructors

### Constructor

```
new ToBTCLNWrapper<T>(

   chainIdentifier, 

   unifiedStorage, 

   unifiedChainEvents, 

   chain, 

   prices, 

   tokens, 

   versionedContracts, 

   lpApi, 

   options?, 

events?): ToBTCLNWrapper<T>;
```

Defined in: [atomiq-sdk/src/swaps/escrow\_swaps/tobtc/ln/ToBTCLNWrapper.ts:100](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts#L100)

#### Parameters

| Parameter            | Type                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `chainIdentifier`    | `string`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `unifiedStorage`     | [`UnifiedSwapStorage`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/UnifiedSwapStorage.md)<`T`>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `unifiedChainEvents` | `UnifiedSwapEventListener`<`T`>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `chain`              | `T`\[`"ChainInterface"`]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `prices`             | [`ISwapPrice`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/ISwapPrice.md)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `tokens`             | `WrapperCtorTokens`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `versionedContracts` | { \[`version`: `string`]: `object`; }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `lpApi`              | `IntermediaryAPI`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `options?`           | `AllOptional`<`ToBTCLNWrapperOptions`>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `events?`            | `EventEmitter`<{ `swapState`: \[[`ISwap`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/ISwap.md)<[`ChainType`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/ChainType.md), `SwapTypeDefinition`<[`ChainType`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/ChainType.md), [`ISwapWrapper`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/ISwapWrapper.md)<[`ChainType`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/ChainType.md), `any`, `ISwapWrapperOptions`>, [`ISwap`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/ISwap.md)<[`ChainType`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/ChainType.md), `any`, `any`>>, `number`>]; }> |

#### Returns

`ToBTCLNWrapper`<`T`>

#### Overrides

[`IToBTCWrapper`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md).[`constructor`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md#constructor)

## Properties

### \_versionedContracts

```
readonly _versionedContracts: object = {};
```

Defined in: [atomiq-sdk/src/swaps/escrow\_swaps/IEscrowSwapWrapper.ts:55](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts#L55)

#### Index Signature

```
[version: string]: object
```

#### Inherited from

[`IToBTCWrapper`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md).[`_versionedContracts`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md#_versionedcontracts)

***

### chainIdentifier

```
readonly chainIdentifier: T["ChainId"];
```

Defined in: [atomiq-sdk/src/swaps/ISwapWrapper.ts:164](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/ISwapWrapper.ts#L164)

Chain identifier string of this wrapper

#### Inherited from

[`IToBTCWrapper`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md).[`chainIdentifier`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md#chainidentifier)

***

### events

```
readonly events: EventEmitter<{

  swapState: [ToBTCLNSwap<T>];

}>;
```

Defined in: [atomiq-sdk/src/swaps/ISwapWrapper.ts:168](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/ISwapWrapper.ts#L168)

Event emitter emitting `"swapState"` event when swap's state changes

#### Inherited from

[`IToBTCWrapper`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md).[`events`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md#events)

***

### TYPE

```
readonly TYPE: TO_BTCLN = SwapType.TO_BTCLN;
```

Defined in: [atomiq-sdk/src/swaps/escrow\_swaps/tobtc/ln/ToBTCLNWrapper.ts:94](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts#L94)

Swap type

#### Overrides

[`IToBTCWrapper`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md).[`TYPE`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md#type)

## Methods

### checkPastSwaps()

```
checkPastSwaps(pastSwaps?, noSave?): Promise<{

  changedSwaps: ToBTCLNSwap<T>[];

  removeSwaps: ToBTCLNSwap<T>[];

}>;
```

Defined in: [atomiq-sdk/src/swaps/ISwapWrapper.ts:424](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/ISwapWrapper.ts#L424)

Runs checks on all the known pending swaps, syncing their state from on-chain data

#### Parameters

| Parameter    | Type                                                                                                          | Description                                                                                                     |
| ------------ | ------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| `pastSwaps?` | [`ToBTCLNSwap`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/ToBTCLNSwap.md)<`T`>\[] | Optional array of past swaps to check, otherwise all relevant swaps will be fetched from the persistent storage |
| `noSave?`    | `boolean`                                                                                                     | Whether to skip saving the swap changes in the persistent storage                                               |

#### Returns

`Promise`<{ `changedSwaps`: [`ToBTCLNSwap`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/ToBTCLNSwap.md)<`T`>\[]; `removeSwaps`: [`ToBTCLNSwap`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/ToBTCLNSwap.md)<`T`>\[]; }>

#### Remarks

Doesn't work properly if you pass non-persisted swaps

#### Inherited from

[`IToBTCWrapper`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md).[`checkPastSwaps`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md#checkpastswaps)

***

### create()

```
create(

   signer, 

   recipient, 

   amountData, 

   lps, 

   options?, 

   additionalParams?, 

   abortSignal?, 

preFetches?): Promise<object[]>;
```

Defined in: [atomiq-sdk/src/swaps/escrow\_swaps/tobtc/ln/ToBTCLNWrapper.ts:372](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts#L372)

Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol, the amount is parsed from the provided lightning network payment request (bolt11 invoice)

#### Parameters

| Parameter                             | Type                                                                                                                                                                                                                                                                                     | Description                                                                              |
| ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| `signer`                              | `string`                                                                                                                                                                                                                                                                                 | Source chain signer address initiating the swap                                          |
| `recipient`                           | `string`                                                                                                                                                                                                                                                                                 | BOLT11 payment request (bitcoin lightning invoice) you wish to pay                       |
| `amountData`                          | `Omit`<[`AmountData`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/AmountData.md), `"amount"`> & `object`                                                                                                                                                  | Token to swap                                                                            |
| `lps`                                 | [`Intermediary`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/Intermediary.md)\[]                                                                                                                                                                               | An array of intermediaries (LPs) to get the quotes from                                  |
| `options?`                            | `ToBTCLNOptions`                                                                                                                                                                                                                                                                         | Optional additional quote options                                                        |
| `additionalParams?`                   | `Record`<`string`, `any`>                                                                                                                                                                                                                                                                | Optional additional parameters sent to the LP when creating the swap                     |
| `abortSignal?`                        | `AbortSignal`                                                                                                                                                                                                                                                                            | Abort signal                                                                             |
| `preFetches?`                         | { `feeRatePromise`: { \[`contractVersion`: `string`]: `Promise`<`string`>; }; `pricePreFetchPromise`: `Promise`<`bigint`>; `signDataPrefetchPromise?`: { \[`contractVersion`: `string`]: `Promise`<`T`\[`"PreFetchVerification"`]>; }; `usdPricePrefetchPromise`: `Promise`<`number`>; } | Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps) |
| `preFetches.feeRatePromise?`          | { \[`contractVersion`: `string`]: `Promise`<`string`>; }                                                                                                                                                                                                                                 | -                                                                                        |
| `preFetches.pricePreFetchPromise?`    | `Promise`<`bigint`>                                                                                                                                                                                                                                                                      | -                                                                                        |
| `preFetches.signDataPrefetchPromise?` | { \[`contractVersion`: `string`]: `Promise`<`T`\[`"PreFetchVerification"`]>; }                                                                                                                                                                                                           | -                                                                                        |
| `preFetches.usdPricePrefetchPromise?` | `Promise`<`number`>                                                                                                                                                                                                                                                                      | -                                                                                        |

#### Returns

`Promise`<`object`\[]>

***

### createViaInvoiceCreateService()

```
createViaInvoiceCreateService(

   signer, 

   invoiceCreateServicePromise, 

   amountData, 

   lps, 

   options?, 

   additionalParams?, 

abortSignal?): Promise<object[]>;
```

Defined in: [atomiq-sdk/src/swaps/escrow\_swaps/tobtc/ln/ToBTCLNWrapper.ts:585](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts#L585)

Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol via invoice creation service. This allows exactIn swaps by requesting the desired fixed amount lightning network invoice from the service.

#### Parameters

| Parameter                     | Type                                                                                                                                                      | Description                                                          |
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| `signer`                      | `string`                                                                                                                                                  | Source chain signer address initiating the swap                      |
| `invoiceCreateServicePromise` | `Promise`<[`LightningInvoiceCreateService`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/LightningInvoiceCreateService.md)> | Service to request destination lightning network invoices from       |
| `amountData`                  | [`AmountData`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/AmountData.md)                                                  | Amount, token and exact input/output data for to swap                |
| `lps`                         | [`Intermediary`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/Intermediary.md)\[]                                                | An array of intermediaries (LPs) to get the quotes from              |
| `options?`                    | `ToBTCLNOptions`                                                                                                                                          | Optional additional quote options                                    |
| `additionalParams?`           | `Record`<`string`, `any`>                                                                                                                                 | Optional additional parameters sent to the LP when creating the swap |
| `abortSignal?`                | `AbortSignal`                                                                                                                                             | Abort signal                                                         |

#### Returns

`Promise`<`object`\[]>

***

### createViaLNURL()

```
createViaLNURL(

   signer, 

   lnurl, 

   amountData, 

   lps, 

   options?, 

   additionalParams?, 

abortSignal?): Promise<object[]>;
```

Defined in: [atomiq-sdk/src/swaps/escrow\_swaps/tobtc/ln/ToBTCLNWrapper.ts:668](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts#L668)

Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol. Pays to an LNURL-pay link. This allows exactIn swaps by requesting the desired fixed amount lightning network invoice from the LNURL service.

#### Parameters

| Parameter           | Type                                                                                                                                          | Description                                                          |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| `signer`            | `string`                                                                                                                                      | Source chain signer address initiating the swap                      |
| `lnurl`             | \| `string` \| [`LNURLPayParamsWithUrl`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/LNURLPayParamsWithUrl.md) | LNURL-pay link of the recipient                                      |
| `amountData`        | [`AmountData`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/AmountData.md)                                      | Amount, token and exact input/output data for to swap                |
| `lps`               | [`Intermediary`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/Intermediary.md)\[]                                    | An array of intermediaries (LPs) to get the quotes from              |
| `options?`          | `ToBTCLNOptions` & `object`                                                                                                                   | Optional additional quote options                                    |
| `additionalParams?` | `Record`<`string`, `any`>                                                                                                                     | Optional additional parameters sent to the LP when creating the swap |
| `abortSignal?`      | `AbortSignal`                                                                                                                                 | Abort signal                                                         |

#### Returns

`Promise`<`object`\[]>

***

### init()

```
init(noTimers, noCheckPastSwaps): Promise<void>;
```

Defined in: [atomiq-sdk/src/swaps/ISwapWrapper.ts:360](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/ISwapWrapper.ts#L360)

Initializes the swap wrapper, needs to be called before any other action can be taken

#### Parameters

| Parameter          | Type      | Default value | Description                                                                                                                                                                                  |
| ------------------ | --------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `noTimers`         | `boolean` | `false`       | Whether to skip scheduling a tick timer for the swaps, if the tick timer is not initiated the swap states depending on e.g. expiry can be out of sync with the actual expiration of the swap |
| `noCheckPastSwaps` | `boolean` | `false`       | Whether to skip checking past swaps on initialization (by default all pending swaps are re-checked on init, and their state is synchronized from the on-chain data)                          |

#### Returns

`Promise`<`void`>

#### Inherited from

[`IToBTCWrapper`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md).[`init`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md#init)

***

### recoverFromSwapDataAndState()

```
recoverFromSwapDataAndState(

   init, 

   state, 

   contractVersion, 

lp?): Promise<ToBTCLNSwap<T>>;
```

Defined in: [atomiq-sdk/src/swaps/escrow\_swaps/tobtc/ln/ToBTCLNWrapper.ts:738](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts#L738)

Recovers a swap from smart chain on-chain data, please note that not all values for the recovered swaps might be populated, as some data is purely off-chain and can never be recovered purely from on-chain data.

#### Parameters

| Parameter          | Type                                                                                                                                                      | Description                                           |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- |
| `init`             | { `data`: `T`\[`"Data"`]; `getInitTxId`: () => `Promise`<`string`>; `getTxBlock`: () => `Promise`<{ `blockHeight`: `number`; `blockTime`: `number`; }>; } | Swap escrow initialization transaction and swap data  |
| `init.data`        | `T`\[`"Data"`]                                                                                                                                            | -                                                     |
| `init.getInitTxId` | () => `Promise`<`string`>                                                                                                                                 | -                                                     |
| `init.getTxBlock`  | () => `Promise`<{ `blockHeight`: `number`; `blockTime`: `number`; }>                                                                                      | -                                                     |
| `state?`           | `SwapCommitState`                                                                                                                                         | Current on-chain state of the swap                    |
| `contractVersion?` | `string`                                                                                                                                                  | -                                                     |
| `lp?`              | [`Intermediary`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/Intermediary.md)                                                   | Intermediary (LP) used as a counterparty for the swap |

#### Returns

`Promise`<[`ToBTCLNSwap`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/ToBTCLNSwap.md)<`T`>>

#### Overrides

[`IToBTCWrapper`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md).[`recoverFromSwapDataAndState`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md#recoverfromswapdataandstate)

***

### stop()

```
stop(): Promise<void>;
```

Defined in: [atomiq-sdk/src/swaps/ISwapWrapper.ts:401](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/ISwapWrapper.ts#L401)

Un-subscribes from event listeners on the smart chain, terminates the tick interval and stops this wrapper

#### Returns

`Promise`<`void`>

#### Inherited from

[`IToBTCWrapper`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md).[`stop`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md#stop)

***

### tick()

```
tick(swaps?, abortSignal?): Promise<void>;
```

Defined in: [atomiq-sdk/src/swaps/ISwapWrapper.ts:459](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/ISwapWrapper.ts#L459)

Invokes ISwap.\_tick on all the known swaps

#### Parameters

| Parameter      | Type                                                                                                          | Description                                                                                                              |
| -------------- | ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `swaps?`       | [`ToBTCLNSwap`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/ToBTCLNSwap.md)<`T`>\[] | Optional array of swaps to invoke `_tick()` on, otherwise all relevant swaps will be fetched from the persistent storage |
| `abortSignal?` | `AbortSignal`                                                                                                 | Abort signal                                                                                                             |

#### Returns

`Promise`<`void`>

#### Inherited from

[`IToBTCWrapper`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md).[`tick`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/IToBTCWrapper.md#tick)
