writeKeyPairSigner
Writes the CryptoKeyPair backing a KeyPairSigner to disk as a JSON array
of 64 bytes, matching the format produced by solana-keygen. The first 32 bytes are the
raw Ed25519 seed (private key) and the last 32 bytes are the raw public key.
Any missing parent directories are created automatically. The written file uses mode
0600 (owner read/write only) to match solana-keygen.
This helper requires a writable filesystem and will throw in environments that don't provide one (such as browsers or React Native).
Parameters
| Parameter | Type | Description |
|---|---|---|
signer | KeyPairSigner | A KeyPairSigner whose underlying CryptoKeyPair is extractable (i.e. created via generateKeyPairSigner(true) or createKeyPairSignerFromBytes(bytes, true)). |
path | string | The destination path on disk. |
config? | Readonly<{ unsafelyOverwriteExistingKeyPair?: boolean; }> | See WriteKeyPairConfig. |
Returns
Promise<void>
Throws
A SolanaError of code
SOLANA_ERROR__KEYS__WRITE_KEY_PAIR_UNSUPPORTED_ENVIRONMENT when called in an
environment without a writable filesystem.
Throws
A SolanaError of code
SOLANA_ERROR__SUBTLE_CRYPTO__CANNOT_EXPORT_NON_EXTRACTABLE_KEY when the signer's
underlying key pair is not extractable.
Examples
Overwriting an existing file requires an explicit opt-in, because doing so permanently destroys the previous key and any funds controlled by it:
See
- writeKeyPair — the lower-level helper from
@solana/keysthat operates on a raw CryptoKeyPair. - createKeyPairSignerFromBytes — the inverse helper that loads a signer from a 64-byte buffer.