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