Skip to main content

Class: BrowserLocalStorageKeyStore

key_stores/browser_local_storage_key_store.BrowserLocalStorageKeyStore

This class is used to store keys in the browsers local storage.

See

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

Example

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

const keyStore = new keyStores.BrowserLocalStorageKeyStore();
const config = {
keyStore, // instance of BrowserLocalStorageKeyStore
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​

  • KeyStore

    ↳ BrowserLocalStorageKeyStore

Constructors​

constructor​

new BrowserLocalStorageKeyStore(localStorage?, prefix?)

Parameters​

NameTypeDefault valueDescription
localStorageanywindow.localStoragedefaults to window.localStorage
prefixstringLOCAL_STORAGE_KEY_PREFIXdefaults to near-api-js:keystore:

Overrides​

KeyStore.constructor

Defined in​

key_stores/browser_local_storage_key_store.ts:38

Methods​

clear​

clear(): Promise<void>

Removes all items that start with prefix from local storage

Returns​

Promise<void>

Overrides​

KeyStore.clear

Defined in​

key_stores/browser_local_storage_key_store.ts:80


getAccounts​

getAccounts(networkId): Promise<string[]>

Gets the account(s) from local storage

Parameters​

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

Returns​

Promise<string[]>

Overrides​

KeyStore.getAccounts

Defined in​

key_stores/browser_local_storage_key_store.ts:107


getKey​

getKey(networkId, accountId): Promise<KeyPair>

Gets a KeyPair from local 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/browser_local_storage_key_store.ts:60


getNetworks​

getNetworks(): Promise<string[]>

Get the network(s) from local storage

Returns​

Promise<string[]>

Overrides​

KeyStore.getNetworks

Defined in​

key_stores/browser_local_storage_key_store.ts:92


removeKey​

removeKey(networkId, accountId): Promise<void>

Removes a KeyPair from local 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/browser_local_storage_key_store.ts:73


setKey​

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

Stores a KeyPair in local storage.

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/browser_local_storage_key_store.ts:50