# OnchainApi

All URIs are relative to *http://localhost*

| Method | HTTP request | Description |
|------------- | ------------- | -------------|
| [**onchainAddress**](OnchainApi.md#onchainaddress) | **POST** /api/v1/onchain/addresses/next | Generate on-chain address |
| [**onchainBalance**](OnchainApi.md#onchainbalance) | **GET** /api/v1/onchain/balance | Get on-chain balance |
| [**onchainDrain**](OnchainApi.md#onchaindrainoperation) | **POST** /api/v1/onchain/drain | Drain on-chain wallet |
| [**onchainSend**](OnchainApi.md#onchainsendoperation) | **POST** /api/v1/onchain/send | Send on-chain payment |
| [**onchainSendMany**](OnchainApi.md#onchainsendmanyoperation) | **POST** /api/v1/onchain/send-many | Send to multiple addresses |
| [**onchainSync**](OnchainApi.md#onchainsync) | **POST** /api/v1/onchain/sync | Sync on-chain wallet |
| [**onchainTransactions**](OnchainApi.md#onchaintransactions) | **GET** /api/v1/onchain/transactions | List on-chain transactions |
| [**onchainUtxos**](OnchainApi.md#onchainutxos) | **GET** /api/v1/onchain/utxos | List on-chain UTXOs |



## onchainAddress

> Address onchainAddress()

Generate on-chain address

Generates a new on-chain receiving address. Each call returns the next unused address from the wallet\&#39;s HD keychain.

### Example

```ts
import {
  Configuration,
  OnchainApi,
} from '@secondts/barkd';
import type { OnchainAddressRequest } from '@secondts/barkd';

async function example() {
  console.log("🚀 Testing @secondts/barkd SDK...");
  const config = new Configuration({ 
    // Configure HTTP bearer authorization: bearer
    accessToken: "YOUR BEARER TOKEN",
  });
  const api = new OnchainApi(config);

  try {
    const data = await api.onchainAddress();
    console.log(data);
  } catch (error) {
    console.error(error);
  }
}

// Run the test
example().catch(console.error);
```

### Parameters

This endpoint does not need any parameter.

### Return type

[**Address**](Address.md)

### Authorization

[bearer](../README.md#bearer)

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: `application/json`


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Returns the on-chain address |  -  |
| **500** | Internal server error |  -  |

[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)


## onchainBalance

> OnchainBalance onchainBalance()

Get on-chain balance

Returns the current on-chain wallet balance, broken down by confirmation status. The &#x60;trusted_spendable_sat&#x60; field is the sum of &#x60;confirmed_sat&#x60; and &#x60;trusted_pending_sat&#x60;—the balance that can be safely spent without risk of double-spend.

### Example

```ts
import {
  Configuration,
  OnchainApi,
} from '@secondts/barkd';
import type { OnchainBalanceRequest } from '@secondts/barkd';

async function example() {
  console.log("🚀 Testing @secondts/barkd SDK...");
  const config = new Configuration({ 
    // Configure HTTP bearer authorization: bearer
    accessToken: "YOUR BEARER TOKEN",
  });
  const api = new OnchainApi(config);

  try {
    const data = await api.onchainBalance();
    console.log(data);
  } catch (error) {
    console.error(error);
  }
}

// Run the test
example().catch(console.error);
```

### Parameters

This endpoint does not need any parameter.

### Return type

[**OnchainBalance**](OnchainBalance.md)

### Authorization

[bearer](../README.md#bearer)

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: `application/json`


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Returns the on-chain balance |  -  |

[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)


## onchainDrain

> Send onchainDrain(onchainDrainRequest)

Drain on-chain wallet

Sends the entire on-chain wallet balance to the specified address. The recipient receives the full balance minus transaction fees. Broadcasts immediately at a fee rate targeting confirmation within three blocks and returns the transaction ID.

### Example

```ts
import {
  Configuration,
  OnchainApi,
} from '@secondts/barkd';
import type { OnchainDrainOperationRequest } from '@secondts/barkd';

async function example() {
  console.log("🚀 Testing @secondts/barkd SDK...");
  const config = new Configuration({ 
    // Configure HTTP bearer authorization: bearer
    accessToken: "YOUR BEARER TOKEN",
  });
  const api = new OnchainApi(config);

  const body = {
    // OnchainDrainRequest
    onchainDrainRequest: ...,
  } satisfies OnchainDrainOperationRequest;

  try {
    const data = await api.onchainDrain(body);
    console.log(data);
  } catch (error) {
    console.error(error);
  }
}

// Run the test
example().catch(console.error);
```

### Parameters


| Name | Type | Description  | Notes |
|------------- | ------------- | ------------- | -------------|
| **onchainDrainRequest** | [OnchainDrainRequest](OnchainDrainRequest.md) |  | |

### Return type

[**Send**](Send.md)

### Authorization

[bearer](../README.md#bearer)

### HTTP request headers

- **Content-Type**: `application/json`
- **Accept**: `application/json`


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Returns the drain result |  -  |
| **400** | The provided destination address is invalid |  -  |
| **500** | Internal server error |  -  |

[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)


## onchainSend

> Send onchainSend(onchainSendRequest)

Send on-chain payment

Sends the specified amount to an on-chain address. Broadcasts the transaction immediately at a fee rate targeting confirmation within three blocks and returns the transaction ID.

### Example

```ts
import {
  Configuration,
  OnchainApi,
} from '@secondts/barkd';
import type { OnchainSendOperationRequest } from '@secondts/barkd';

async function example() {
  console.log("🚀 Testing @secondts/barkd SDK...");
  const config = new Configuration({ 
    // Configure HTTP bearer authorization: bearer
    accessToken: "YOUR BEARER TOKEN",
  });
  const api = new OnchainApi(config);

  const body = {
    // OnchainSendRequest
    onchainSendRequest: ...,
  } satisfies OnchainSendOperationRequest;

  try {
    const data = await api.onchainSend(body);
    console.log(data);
  } catch (error) {
    console.error(error);
  }
}

// Run the test
example().catch(console.error);
```

### Parameters


| Name | Type | Description  | Notes |
|------------- | ------------- | ------------- | -------------|
| **onchainSendRequest** | [OnchainSendRequest](OnchainSendRequest.md) |  | |

### Return type

[**Send**](Send.md)

### Authorization

[bearer](../README.md#bearer)

### HTTP request headers

- **Content-Type**: `application/json`
- **Accept**: `application/json`


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Returns the send result |  -  |
| **400** | The provided destination address is invalid |  -  |
| **500** | Internal server error |  -  |

[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)


## onchainSendMany

> Send onchainSendMany(onchainSendManyRequest)

Send to multiple addresses

Batches multiple payments into a single on-chain transaction. Each destination is formatted as &#x60;address:amount&#x60;. Broadcasts the transaction immediately at a fee rate targeting confirmation within three blocks and returns the transaction ID.

### Example

```ts
import {
  Configuration,
  OnchainApi,
} from '@secondts/barkd';
import type { OnchainSendManyOperationRequest } from '@secondts/barkd';

async function example() {
  console.log("🚀 Testing @secondts/barkd SDK...");
  const config = new Configuration({ 
    // Configure HTTP bearer authorization: bearer
    accessToken: "YOUR BEARER TOKEN",
  });
  const api = new OnchainApi(config);

  const body = {
    // OnchainSendManyRequest
    onchainSendManyRequest: ...,
  } satisfies OnchainSendManyOperationRequest;

  try {
    const data = await api.onchainSendMany(body);
    console.log(data);
  } catch (error) {
    console.error(error);
  }
}

// Run the test
example().catch(console.error);
```

### Parameters


| Name | Type | Description  | Notes |
|------------- | ------------- | ------------- | -------------|
| **onchainSendManyRequest** | [OnchainSendManyRequest](OnchainSendManyRequest.md) |  | |

### Return type

[**Send**](Send.md)

### Authorization

[bearer](../README.md#bearer)

### HTTP request headers

- **Content-Type**: `application/json`
- **Accept**: `application/json`


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Returns the send result |  -  |
| **400** | One of the provided destinations is invalid |  -  |
| **500** | Internal server error |  -  |

[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)


## onchainSync

> onchainSync()

Sync on-chain wallet

Syncs the on-chain wallet state with the chain source. Fetches new blocks and transactions, updates the UTXO set, and re-submits any stale unconfirmed transactions to the mempool.

### Example

```ts
import {
  Configuration,
  OnchainApi,
} from '@secondts/barkd';
import type { OnchainSyncRequest } from '@secondts/barkd';

async function example() {
  console.log("🚀 Testing @secondts/barkd SDK...");
  const config = new Configuration({ 
    // Configure HTTP bearer authorization: bearer
    accessToken: "YOUR BEARER TOKEN",
  });
  const api = new OnchainApi(config);

  try {
    const data = await api.onchainSync();
    console.log(data);
  } catch (error) {
    console.error(error);
  }
}

// Run the test
example().catch(console.error);
```

### Parameters

This endpoint does not need any parameter.

### Return type

`void` (Empty response body)

### Authorization

[bearer](../README.md#bearer)

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: `application/json`


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Synced on-chain wallet |  -  |
| **500** | Internal server error |  -  |

[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)


## onchainTransactions

> Array&lt;WalletTxInfo&gt; onchainTransactions()

List on-chain transactions

Returns all on-chain wallet transactions, ordered from oldest to newest. Each entry includes the raw transaction, its fee (when known), the wallet\&#39;s net balance change, and confirmation status. The fee is &#x60;null&#x60; for inbound or collaboratively-funded transactions whose foreign prevouts BDK has not indexed.

### Example

```ts
import {
  Configuration,
  OnchainApi,
} from '@secondts/barkd';
import type { OnchainTransactionsRequest } from '@secondts/barkd';

async function example() {
  console.log("🚀 Testing @secondts/barkd SDK...");
  const config = new Configuration({ 
    // Configure HTTP bearer authorization: bearer
    accessToken: "YOUR BEARER TOKEN",
  });
  const api = new OnchainApi(config);

  try {
    const data = await api.onchainTransactions();
    console.log(data);
  } catch (error) {
    console.error(error);
  }
}

// Run the test
example().catch(console.error);
```

### Parameters

This endpoint does not need any parameter.

### Return type

[**Array&lt;WalletTxInfo&gt;**](WalletTxInfo.md)

### Authorization

[bearer](../README.md#bearer)

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: `application/json`


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Returns the on-chain transactions |  -  |

[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)


## onchainUtxos

> Array&lt;UtxoInfo&gt; onchainUtxos()

List on-chain UTXOs

Returns all UTXOs in the on-chain wallet. Each entry includes the outpoint, amount, and confirmation height (if confirmed).

### Example

```ts
import {
  Configuration,
  OnchainApi,
} from '@secondts/barkd';
import type { OnchainUtxosRequest } from '@secondts/barkd';

async function example() {
  console.log("🚀 Testing @secondts/barkd SDK...");
  const config = new Configuration({ 
    // Configure HTTP bearer authorization: bearer
    accessToken: "YOUR BEARER TOKEN",
  });
  const api = new OnchainApi(config);

  try {
    const data = await api.onchainUtxos();
    console.log(data);
  } catch (error) {
    console.error(error);
  }
}

// Run the test
example().catch(console.error);
```

### Parameters

This endpoint does not need any parameter.

### Return type

[**Array&lt;UtxoInfo&gt;**](UtxoInfo.md)

### Authorization

[bearer](../README.md#bearer)

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: `application/json`


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Returns the on-chain UTXOs |  -  |

[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)

