# OnchainForGasWrapper\<T>

Defined in: [atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasWrapper.ts:27](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/trusted/onchain/OnchainForGasWrapper.ts#L27)

Trusted swap for Bitcoin -> Smart chains, to be used for minor amounts to get gas tokens on the destination chain, which is only needed for Solana, which still uses legacy swaps

## Extends

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

## Type Parameters

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

## Constructors

### Constructor

```
new OnchainForGasWrapper<T>(

   chainIdentifier, 

   unifiedStorage, 

   unifiedChainEvents, 

   chain, 

   prices, 

   tokens, 

   btcRpc, 

   lpApi, 

   options, 

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

Defined in: [atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasWrapper.ts:64](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/trusted/onchain/OnchainForGasWrapper.ts#L64)

#### Parameters

| Parameter            | Type                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Description                                                     |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| `chainIdentifier`    | `string`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                 |
| `unifiedStorage`     | [`UnifiedSwapStorage`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/UnifiedSwapStorage.md)<`T`>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Storage interface for the current environment                   |
| `unifiedChainEvents` | `UnifiedSwapEventListener`<`T`>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | On-chain event listener                                         |
| `chain`              | `T`\[`"ChainInterface"`]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                 |
| `prices`             | [`ISwapPrice`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/ISwapPrice.md)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | Pricing to use                                                  |
| `tokens`             | `WrapperCtorTokens`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                                                                 |
| `btcRpc`             | [`BitcoinRpcWithAddressIndex`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/BitcoinRpcWithAddressIndex.md)<`any`>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | Bitcoin RPC which also supports getting transactions by txoHash |
| `lpApi`              | `IntermediaryAPI`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |                                                                 |
| `options`            | `OnchainForGasWrapperOptions`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                 |
| `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`>]; }> | Instance to use for emitting events                             |

#### Returns

`OnchainForGasWrapper`<`T`>

#### Overrides

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

## Properties

### 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

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

***

### events

```
readonly events: EventEmitter<{

  swapState: [OnchainForGasSwap<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

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

***

### TYPE

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

Defined in: [atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasWrapper.ts:28](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/trusted/onchain/OnchainForGasWrapper.ts#L28)

Swap type

#### Overrides

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

## Methods

### checkPastSwaps()

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

  changedSwaps: OnchainForGasSwap<T>[];

  removeSwaps: OnchainForGasSwap<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?` | [`OnchainForGasSwap`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/OnchainForGasSwap.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`: [`OnchainForGasSwap`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/OnchainForGasSwap.md)<`T`>\[]; `removeSwaps`: [`OnchainForGasSwap`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/OnchainForGasSwap.md)<`T`>\[]; }>

#### Remarks

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

#### Inherited from

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

***

### create()

```
create(

   recipient, 

   amount, 

   lpOrUrl, 

refundAddress?): Promise<OnchainForGasSwap<T>>;
```

Defined in: [atomiq-sdk/src/swaps/trusted/onchain/OnchainForGasWrapper.ts:89](https://github.com/atomiqlabs/atomiq-sdk/blob/786509324f7f09c427e9ccfe527d82e496f06af5/src/swaps/trusted/onchain/OnchainForGasWrapper.ts#L89)

Returns a newly created trusted Bitcoin on-chain -> Smart chain swap, receiving the specified amount of native token on the destination chain.

#### Parameters

| Parameter        | Type                                                                                                                | Description                                                                                |
| ---------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| `recipient`      | `string`                                                                                                            | Address of the recipient on the smart chain destination chain                              |
| `amount`         | `bigint`                                                                                                            | Amount of native token to receive in base units                                            |
| `lpOrUrl`        | `string` \| [`Intermediary`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/Intermediary.md) | Intermediary (LP) to use for the swap                                                      |
| `refundAddress?` | `string`                                                                                                            | Bitcoin address to receive refund on in case the intermediary (LP) cannot execute the swap |

#### Returns

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

***

### 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

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

***

### 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

[`ISwapWrapper`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/ISwapWrapper.md).[`stop`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/ISwapWrapper.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?`       | [`OnchainForGasSwap`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/OnchainForGasSwap.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

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