⛏️fetchWalletFromPrivateKey

Description

The fetchWalletfromPrivateKey function generates a key pair (public key and private key) from a given private key. It makes use of the CasperClient library and the Ed25519 algorithm to generate the key pair.

Parameters

NameTypeDescription

privateKey

string

The private key to be used to generate the key pair

RPC_API

string

The RPC API to be used by the CasperClient

Response

NameTypeDescription

keyPair

object

An object containing the generated public key and private key as buffers

Example Request and Response

Prerequisites

Before making requests with Nest SDK, you must have it installed.

You can install Nest SDK using either npm or yarn. Use the following commands to install Nest SDK:

npm install @nest25/casper-lib
OR
yarn add @nest25/casper-lib

Request

Here is an example of how to make a fetchWalletfromPrivateKey request using the Nest SDK:

// import Nest25 Casper library
const { Casper } = require('@nest25/casper-lib');
// create a new Casper instance
const casper = new Casper();

// set testnet variables
const privateKey = 'your-private-key';
const RPC_API = 'https://rpc.testnet.casperlabs.io/rpc';

async function main() {
  // fetch wallet from private key
  let { keyPair } = await casper.fetchWalletfromPrivateKey(privateKey, RPC_API);
  console.log(keyPair);
}
// call main function
main();

```

Response

  {
        keyPair: t {
          publicKey: t { isCLValue: true, data: [Uint8Array], tag: 1 },
          privateKey: Uint8Array(64) [
            136, 103,  79,  12,  53,  66, 163, 104,  97, 238, 253,
            201,  63, 217,  28, 226,   8,  28, 163, 193, 111, 158,
            233, 203, 206, 234, 204, 112,  91, 196, 214, 176,  58,
             21, 106,  80, 252,  98, 132, 186,  67, 106, 237, 234,
            249, 107,  85, 172,  26,  12,  87, 238, 159, 138,  70,
            191,  28, 101,  24, 175, 233, 178, 245, 108
          ],
          signatureAlgorithm: 'ed25519'
        }
      }

Use Cases

  • Crypto Wallets: The function can be used by crypto wallets to generate key pairs from private keys.

  • Blockchain Applications: The function can be used by blockchain applications to interact with the Casper network and sign transactions with generated key pairs.

Last updated