Skip to content

useExportPrivateKey

Hook for exporting a private key

Import

import { useExportPrivateKey } from '@zerodev/wallet-react'

Usage

import { useExportPrivateKey } from '@zerodev/wallet-react'
 
function ExportKey() {
  const exportPrivateKey = useExportPrivateKey()
 
  return (
    <div>
      <div id="key-container" style={{ minHeight: '100px' }} />
 
      <button
        onClick={() =>
          exportPrivateKey.mutateAsync({
            iframeContainerId: 'key-container',
            keyFormat: 'Hexadecimal',
            iframeStyles: {
              width: '400px',
              height: '100px',
              border: 'none',
            },
          })
        }
        disabled={exportPrivateKey.isPending}
      >
        {exportPrivateKey.isPending ? 'Exporting...' : 'Export Private Key'}
      </button>
    </div>
  )
}

Parameters

iframeContainerId

string

Required. The id of the DOM element where the secure export iframe will be rendered. The private key is displayed inside this iframe.

iframeStyles

Record<string, string> | undefined

Optional CSS styles to apply to the export iframe element.

address

string | undefined

The address of the account to export the private key for. If omitted, uses the currently active account.

keyFormat

'Hexadecimal' | 'Solana' | undefined

The format for the exported private key.

  • 'Hexadecimal' — Standard hex-encoded private key (default)
  • 'Solana' — Solana-compatible key format

connector

Connector | undefined

The Wagmi connector to export the key for. If omitted, uses the currently active connector.

Return Types

TanStack Query mutation docs

mutate

(variables: { iframeContainerId: string; iframeStyles?: Record<string, string>; address?: string; keyFormat?: 'Hexadecimal' | 'Solana'; connector?: Connector }) => void

The mutation function to initiate the private key export. Renders a secure iframe containing the private key in the specified container.

mutateAsync

(variables: { iframeContainerId: string; iframeStyles?: Record<string, string>; address?: string; keyFormat?: 'Hexadecimal' | 'Solana'; connector?: Connector }) => Promise<void>

Similar to mutate but returns a promise. Resolves when the export iframe is rendered.

data

void

This mutation does not return data. The private key is displayed inside the secure iframe.

error

Error | null

The error object for the mutation, if an error was encountered.

isError / isIdle / isPending / isSuccess

boolean

Boolean variables derived from status.

isPaused

boolean

  • will be true if the mutation has been paused.
  • see Network Mode for more information.

status

'idle' | 'pending' | 'error' | 'success'

  • 'idle' initial status prior to the mutation function executing.
  • 'pending' if the mutation is currently executing.
  • 'error' if the last mutation attempt resulted in an error.
  • 'success' if the last mutation attempt was successful.

reset

() => void

A function to clean the mutation internal state (e.g. it resets the mutation to its initial state).