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

In memory 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 intended to be used for development workflows.

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

If you require server-side signing of operations on 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

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

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. can do so as follows:

import { TezosToolkit } from '@taquito/taquito'
import { importKey } from '@taquito/taquito-signer';
const Tezos = new TezosToolkit('https://YOUR_PREFERRED_TESTNET_RPC_URL');
// A key faucet, similar to what is available from https://faucet.tzalpha.net/
const FAUCET_KEY = {
mnemonic: [
'cart',
'will',
'page',
'bench',
'notice',
'leisure',
'penalty',
'medal',
'define',
'odor',
'ride',
'devote',
'cannon',
'setup',
'rescue',
],
secret: '35f266fbf0fca752da1342fdfc745a9c608e7b20',
amount: '4219352756',
pkh: 'tz1YBMFg1nLAPxBE6djnCPbMRH5PLXQWt8Mg',
password: 'Fa26j580dQ',
email: 'jxmjvauo.guddusns@tezos.example.org',
};
importKey(
Tezos,
FAUCET_KEY.email,
FAUCET_KEY.password,
FAUCET_KEY.mnemonic.join(' '),
FAUCET_KEY.secret
);
// Your Tezos instance is now operably configured for signing with the faucet key.

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

note

Operation will be signed automatically using the signer (no prompt)

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('alices_secret_key')