> For the complete documentation index, see [llms.txt](https://docs.non-obvious.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.non-obvious.ai/sdks-guide/blockchain-sdks/wallet-sdk/getkeys/btc.md).

# 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 NO.AI SDK, you must have it installed.

You can install NO.AI SDK using either **`npm`** or **`yarn`**. Use the following commands to install NO.AI 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 NO.AI 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.non-obvious.ai/sdks-guide/blockchain-sdks/wallet-sdk/getkeys/btc.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
