Skip to main content
Version: 20.0.0

In Memory Signer

Warning

Storing private keys in memory is suitable for development workflows but risky for production use-cases! Use the InMemorySigner appropriately given your risk profile More information on why can be found here

Inmemory signer is a local signer implementation that allows you to directly use a private key in your browser or your nodejs app.

This signer implementation is for development workflows.

Using the InMemorySigner for operations on mainnet where your system uses tokens of real value is discouraged.

If you require the server-side signing of operations on the mainnet, we recommend exploring the use of the Remote Signer package in conjunction with an HSM remote signer such as Signatory or TacoInfra's Remote Signer.

Usage

Loading an unencrypted private key

If you configure Taquito this way, you will now be able to use every function that needs signing support.

import { InMemorySigner } from '@taquito/signer';
import { TezosToolkit } from '@taquito/taquito';
const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL');
Tezos.setProvider({ signer: await InMemorySigner.fromSecretKey('your_private_key') });
note

The operation will be signed automatically using the signer (no prompt)

The fromSecretKey method takes a secret that is base58 encoded as a parameter. Here are three examples with unencrypted private keys:

Live Editor
Result
Live Editor
Result

When required, Taquito offers the b58cencode function allowing to encode the secret in base58. The parameters of the function are the secret, that can be a hex string or an Uint8Array, and the desired prefix. Here is an example with a hex string:

Live Editor
Result

Loading an encrypted private key with a passphrase

If your private key is encrypted, you can specify a passphrase to decrypt it. Doing so will automatically decrypt the key and allow you to use the signer to sign transactions.

import { InMemorySigner } from '@taquito/signer';
import { TezosToolkit } from '@taquito/taquito';
const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL');
Tezos.setProvider({
signer: await InMemorySigner.fromSecretKey('your_private_key', 'your_passphrase'),
});

Here are three examples with encrypted private keys where the passphrase used is test:

Live Editor
Result
Live Editor
Result
Live Editor
Result

Loading a mnemonic

The fromMnemonic method takes the mnemonic, password, derivationPath, and curve as parameters. Here is an example of an instantiation of an InMemorySigner.fromMnemonic

derivation path MUST start with "44'/1729'/"

With ed25519 default derivation path (Reminder Must be hardened with either h or ')

Live Editor
Result

With a non-default derivation path non-hardened with a tz2 address

Live Editor
Result

Using a testnet faucet key

To load a faucet key (available from https://faucet.tzalpha.net/) for working a public testnet use the importKey function.

note

Since August 2022, the JSON faucets we used to import with the importKey function are no longer available. You can use the following link to fund an address on the different testnets: https://teztnets.com/.

A simple factory multiple keys/wallets

If you require to sign operations with many different keys, then implementing a factory function can be useful. The signerFactory function example creates a new Tezos instance. Use the Tezos instance for signing, and discard it when complete.

import { InMemorySigner } from '@taquito/signer';
import { TezosToolkit } from '@taquito/taquito';
const signerFactory = async (rpcUrl: string, pk: string) => {
const Tezos = new TezosToolkit(rpcUrl);
await Tezos.setProvider({ signer: await InMemorySigner.fromSecretKey(pk) });
return Tezos;
};
const bob = await signerFactory('bobs_secret_key');
const alice = await signerFactory('alice_secret_key');

Provide detailed feedback