> For the complete documentation index, see [llms.txt](https://docs.usemeta.fi/js-sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.usemeta.fi/js-sdk/sdk-reference/other-functions/retrieveprivatekey.md).

# RetrievePrivateKey

## Description

Downloads the user's private key as a `.txt` file. Please ensure that the user is made aware of the risks of exporting their private key before allowing them to pick this option.

## Details

### Signature

`async RetrievePrivateKey(apiKey, walletAddress)`

### Arguments

<table><thead><tr><th width="258">Parameter</th><th width="114">Type</th><th>Definition</th></tr></thead><tbody><tr><td><code>apiKey</code></td><td>String</td><td>The API Key generated from the <a href="https://developer-test.usemeta.fi/">Developer Portal</a></td></tr><tr><td><code>walletAddress</code></td><td>String</td><td>The public wallet address for which you would like to export the private key. The wallet address can be retrieved from the RetrieveUser endpoint.</td></tr></tbody></table>

### Return Value

This function returns a `Promise` that resolves to the following object:

```json
{
    "statusCode": 1/0,
    "data": "data" // always null
    "error": "error" // error if any, else null
}
```

## Example

{% code title="" lineNumbers="true" %}

```jsx
import { RetrievePrivateKey } from '@metafi/metafi-js-package';

function App() {

    const handleRetrievePrivateKey = async () => {
        var result = await RetrievePrivateKey("WALLET-ADDRESS", "YOUR-API-KEY");
        console.log("result after retrieving private key", result);
    }
    
    return (
        <div>
	    <button onClick={handleRetrievePrivateKey}>Download Your Private Key</button>
        </div>
    );
}

export default App;

```

{% endcode %}


---

# 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.usemeta.fi/js-sdk/sdk-reference/other-functions/retrieveprivatekey.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.
