Documentation
Core Concepts
Wallet

Wallet

You can instantiate a wallet object from seed without binding it with a Lucid object by calling the walletFromSeed function. For example, to use it with an emulator or to run test scenarios.

Generate Seed Phrase

import { generateSeedPhrase } from "@lucid-evolution/lucid";
 
const seedPhrase = generateSeedPhrase(); // BIP-39
console.log(seedPhrase);

Create Wallet

import { walletFromSeed } from "@lucid-evolution/lucid";
 
const seedPhrase = "your seed phrase here ...";
const wallet = walletFromSeed(seedPhrase);
console.log(wallet); // { address, rewardAddress, paymentKey, stakeKey }

Discover Own Used Tx Key Hashes

There is also a utility function associated with the wallet module to discover which key hashes are used from a transaction object limited to the specified UTXOs.

import { discoverOwnUsedTxKeyHashes } from "@lucid-evolution/lucid";
 
const tx: TxSignBuilder = await lucid
  .newTx()
  // ... build your transaction
  .complete();
const ownKeyHashes: Array<KeyHash> = ["KeyHash1", "KeyHash2", "OtherKeyHash"];
const ownUtxos: Array<UTxO> = utxos;
 
const usedKeyHashes: Array<KeyHash> = discoverOwnUsedTxKeyHashes(
  tx.toTransaction(),
  ownKeyHashes,
  ownUtxos,
);
console.log(usedKeyHashes); // ["KeyHash1", "KeyHash2"]

Authoritative UTxO overrides

overrideUTxOs treats the supplied array as the complete wallet state, including an empty array. This is useful while chaining transactions or while a provider indexer is catching up.

lucid.overrideUTxOs([]); // The wallet is authoritatively empty.
 
// Resume querying the selected wallet's provider or wallet API.
lucid.clearUTxOOverride();

Overrides remain active until replaced or explicitly cleared.

Collateral selection

Transactions that run Plutus scripts need collateral. When the selected wallet names its own collateral, as a CIP-30 wallet does through getCollateral, complete() uses those UTxOs first:

  1. The wallet's candidates are limited to the active UTxO override, or to presetWalletInputs when given, so a UTxO spent by a pending chained transaction is not reused.
  2. If the candidates cover the required collateral, they are used. A candidate holding exactly the required amount in ADA is used without a collateral return.
  3. Otherwise, including when the wallet returns no collateral or the call fails, collateral is selected from the wallet's UTxOs.

Wallets without getCollateral, such as seed and private key wallets, always use step 3.