Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.magic.link/llms.txt

Use this file to discover all available pages before exploring further.

SDK Method

This method is currently only available through our web, React Native, and Android SDKs. For all other SDKs, refer to our Reveal Page section below.
pk-reveal-updated
You can use Magic’s user.revealEVMPrivateKey method to allow your users to view their EVM private keys. Implementing this method will allow your end users to back up their private keys or take them to another wallet. Neither Magic nor the developer can see this key; only the end user can.
Breaking Change: As of SDK version 31.0.0 (JavaScript) and 32.0.0 (React Native), revealPrivateKey() has been renamed to revealEVMPrivateKey() for EVM chains. For non-EVM chains, use the specific extension’s revealPrivateKey() method instead. The Android SDK continues to use user.revealPrivateKey().

Usage

Once you have verified the correct setup of the Magic SDK and successfully authenticated the user, the reveal private key modal can then be displayed by calling the appropriate method:
Important: Implementing this SDK method will allow your end users to access their private key. Be sure to read through this document carefully before implementing.

EVM Chains (Web & React Native)

JavaScript
import { Magic } from "magic-sdk";

const magic = new Magic('PUBLISHABLE_API_KEY');

try {
  await magic.user.revealEVMPrivateKey();
} catch {
  // Handle errors if required!
}

Non-EVM Chains (Blockchain Extensions)

For non-EVM chains, use the specific extension’s revealPrivateKey method:
JavaScript
import { Magic } from "magic-sdk";
import { SolanaExtension } from "@magic-ext/solana";
import { BitcoinExtension } from "@magic-ext/bitcoin";

const magic = new Magic('PUBLISHABLE_API_KEY', {
  extensions: [
    new SolanaExtension({ rpcUrl: 'SOLANA_RPC_NODE_URL' }),
    new BitcoinExtension({ rpcUrl: 'BITCOIN_RPC_NODE_URL', network: 'testnet' }),
  ],
});

// Reveal Solana private key
try {
  await magic.solana.revealPrivateKey();
} catch {
  // Handle errors if required!
}

// Reveal Bitcoin private key
try {
  await magic.bitcoin.revealPrivateKey();
} catch {
  // Handle errors if required!
}

Android SDK

The Android SDK continues to use the original method:
Kotlin
try {
    magic.user.revealPrivateKey()
} catch (e: Exception) {
    // Handle errors if required!
}