Simple in-memory keystore for mainly for testing purposes.

See

https://docs.near.org/docs/develop/front-end/naj-quick-reference#key-store

Example

import { connect, keyStores, utils } from 'near-api-js';

const privateKey = '.......';
const keyPair = utils.KeyPair.fromString(privateKey);

const keyStore = new keyStores.InMemoryKeyStore();
keyStore.setKey('testnet', 'example-account.testnet', keyPair);

const config = {
keyStore, // instance of InMemoryKeyStore
networkId: 'testnet',
nodeUrl: 'https://rpc.testnet.near.org',
walletUrl: 'https://wallet.testnet.near.org',
helperUrl: 'https://helper.testnet.near.org',
explorerUrl: 'https://explorer.testnet.near.org'
};

// inside an async function
const near = await connect(config)

Hierarchy (view full)

Constructors

Methods

  • Gets the account(s) from in-memory storage

    Parameters

    • networkId: string

      The targeted network. (ex. default, betanet, etc…)

    Returns Promise<string[]>

  • Gets a KeyPair from in-memory storage

    Parameters

    • networkId: string

      The targeted network. (ex. default, betanet, etc…)

    • accountId: string

      The NEAR account tied to the key pair

    Returns Promise<KeyPair>

  • Removes a KeyPair from in-memory storage

    Parameters

    • networkId: string

      The targeted network. (ex. default, betanet, etc…)

    • accountId: string

      The NEAR account tied to the key pair

    Returns Promise<void>

  • Stores a KeyPair in in-memory storage item

    Parameters

    • networkId: string

      The targeted network. (ex. default, betanet, etc…)

    • accountId: string

      The NEAR account tied to the key pair

    • keyPair: KeyPair

      The key pair to store in local storage

    Returns Promise<void>