# btc

## Description

The `getKeys` function generates a Bitcoin wallet address and its corresponding private key based on a given mnemonic phrase and environment (mainnet or testnet).

## Parameters

| Name       | Type   | Description                                                      |
| ---------- | ------ | ---------------------------------------------------------------- |
| `mnemonic` | string | The mnemonic phrase used to generate the wallet                  |
| `env`      | string | The environment (mainnet or testnet) used to generate the wallet |

## Response

| Name                | Type   | Description                                                                                       |
| ------------------- | ------ | ------------------------------------------------------------------------------------------------- |
| `code`              | number | 1 if successful, 0 if there was an error                                                          |
| `result`            | object | An object containing the Bitcoin private key and address if code is 1, otherwise an error message |
| `result.privateKey` | string | The private key of the generated wallet                                                           |
| `result.address`    | string | The Bitcoin address of the generated wallet                                                       |
| `error`             | string | The error message if code is 0                                                                    |

## Example Request and Response

### Prerequisites

Before making requests with Volary SDK, you must have it installed.

You can install Volary SDK using either **`npm`** or **`yarn`**. Use the following commands to install Volary SDK:

```sh
npm install @nest25/wallet-lib
OR
yarn add @nest25/wallet-lib
```

### Request

Here is an example of how to make a `getKeys` request using the Volary SDK:

```javascript
// import Nest SDK
import { Wallet } from 'nest25/wallet-lib';

// Create a new instance of the Wallet class
const wallet = new Wallet('mainnet');
// test mnemonic for BTC mainnet (use the createWallet function to get one)
const testMnemonic = 'forest almost like horn board swamp wish wedding rough number live when';

const main = async () => {
  // get the keys for the test mnemonic
  const response = await wallet.getKeys('btc', testMnemonic);
  // log the response
  console.log(response);
};

main();

```

### Response

```sh
{
        code: 1,
        result: {
          privateKey: 'L4TDvVVhGfdeKqDYSb79b9TEQpMVsLrVTpqqXhgH7eoEyQaSvqc1',
          address: '12UfEfFeY5oBFc1z2o8y1bzVj3D5TNFaHm'
        }
}
```

## Use Cases

* **Bitcoin Wallet:** This function can be used by a cryptocurrency wallet provider to generate a Bitcoin wallet for a user based on their mnemonic phrase and the desired environment.
* **Online Merchants:** This function can be used by an online merchant to generate a Bitcoin address for receiving payments from customers on the mainnet or testnet.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.volary.io/sdks-guide/blockchain-sdks/wallet-sdk/getkeys/btc.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
