Skip to main content

Class: InMemoryKeyStore

key_stores/in_memory_key_store.InMemoryKeyStore

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​

Constructors​

constructor​

new InMemoryKeyStore()

Overrides​

KeyStore.constructor

Defined in​

key_stores/in_memory_key_store.ts:35

Methods​

clear​

clear(): Promise<void>

Removes all KeyPair from in-memory storage

Returns​

Promise<void>

Overrides​

KeyStore.clear

Defined in​

key_stores/in_memory_key_store.ts:76


getAccounts​

getAccounts(networkId): Promise<string[]>

Gets the account(s) from in-memory storage

Parameters​

NameTypeDescription
networkIdstringThe targeted network. (ex. default, betanet, etc…)

Returns​

Promise<string[]>

Overrides​

KeyStore.getAccounts

Defined in​

key_stores/in_memory_key_store.ts:97


getKey​

getKey(networkId, accountId): Promise<KeyPair>

Gets a KeyPair from in-memory storage

Parameters​

NameTypeDescription
networkIdstringThe targeted network. (ex. default, betanet, etc…)
accountIdstringThe NEAR account tied to the key pair

Returns​

Promise<KeyPair>

Overrides​

KeyStore.getKey

Defined in​

key_stores/in_memory_key_store.ts:56


getNetworks​

getNetworks(): Promise<string[]>

Get the network(s) from in-memory storage

Returns​

Promise<string[]>

Overrides​

KeyStore.getNetworks

Defined in​

key_stores/in_memory_key_store.ts:84


removeKey​

removeKey(networkId, accountId): Promise<void>

Removes a KeyPair from in-memory storage

Parameters​

NameTypeDescription
networkIdstringThe targeted network. (ex. default, betanet, etc…)
accountIdstringThe NEAR account tied to the key pair

Returns​

Promise<void>

Overrides​

KeyStore.removeKey

Defined in​

key_stores/in_memory_key_store.ts:69


setKey​

setKey(networkId, accountId, keyPair): Promise<void>

Stores a KeyPair in in-memory storage item

Parameters​

NameTypeDescription
networkIdstringThe targeted network. (ex. default, betanet, etc…)
accountIdstringThe NEAR account tied to the key pair
keyPairKeyPairThe key pair to store in local storage

Returns​

Promise<void>

Overrides​

KeyStore.setKey

Defined in​

key_stores/in_memory_key_store.ts:46