diff --git a/content/cookbook/wallets/restore-keypair.md b/content/cookbook/wallets/restore-keypair.md index 7cb5d570f..439a7c6dd 100644 --- a/content/cookbook/wallets/restore-keypair.md +++ b/content/cookbook/wallets/restore-keypair.md @@ -9,7 +9,30 @@ secret to test out your dApp. ## From Bytes -```typescript filename="restore-keypair-from-bytes.ts" + + + + +```typescript +import { createKeyPairFromBytes } from "@solana/web3.js"; + +const keypair = await createKeyPairFromBytes( + new Uint8Array([ + 174, 47, 154, 16, 202, 193, 206, 113, 199, 190, 53, 133, 169, 175, 31, 56, + 222, 53, 138, 189, 224, 216, 117, 173, 10, 149, 53, 45, 73, 251, 237, 246, + 15, 185, 186, 82, 177, 240, 148, 69, 241, 227, 167, 80, 141, 89, 240, 121, + 121, 35, 172, 247, 68, 251, 226, 218, 48, 63, 176, 109, 168, 89, 238, 135, + ]), +); + +console.log(keypair); +``` + + + + + +```typescript import { Keypair } from "@solana/web3.js"; const keypair = Keypair.fromSecretKey( @@ -22,15 +45,43 @@ const keypair = Keypair.fromSecretKey( ); ``` + + + + ## From base58 String -```typescript filename="restore-keypair-from-base58.ts -import { Keypair } from "@solana/web3.js"; -import * as bs58 from "bs58"; + -const keypair = Keypair.fromSecretKey( + + +```typescript +import { createKeyPairFromBytes } from "@solana/web3.js"; +import bs58 from "bs58"; + +const keypair = await createKeyPairFromBytes( bs58.decode( "5MaiiCavjCmn9Hs1o3eznqDEhRwxo7pXiAYez7keQUviUkauRiTMD8DrESdrNjN8zd9mTmVhRvBJeg5vhyvgrAhG", ), ); + +console.log(keypair); ``` + + + + + +```typescript +import { createKeyPairFromBytes, getBase58Encoder } from "@solana/web3.js"; + +const keypair = await createKeyPairFromBytes( + getBase58Encoder().decode("5MaiiCavjCmn9Hs1o3eznqDEhRwxo7pXiAYez7keQUviUkauRiTMD8DrESdrNjN8zd9mTmVhRvBJeg5vhyvgrAhG") +); + +console.log(keypair); +``` + + + +