Create & Choose Wallets
Create a wallet
You are provided with multiple options to create and import a wallet:
- Private Key
- Seed Phrase
Generate a new private key:
import { generatePrivateKey } from "@lucid-evolution/lucid";
const privateKey = generatePrivateKey(); // Bech32 encoded private key
// console.log(privateKey);
Generate a new seed phrase (mnemonic):
import { generateSeedPhrase } from "@lucid-evolution/lucid";
const seedPhrase = generateSeedPhrase(); // BIP-39
// console.log(seedPhrase);
Choosing Wallet
Use any suitable method to select a wallet and interact with the blockchain through it:
- Private Key
- Seed Phrase
- Wallet API
- Address-only
Select a wallet using a private key:
lucid.selectWallet.fromPrivateKey(privateKey);
Select a wallet using a seed phrase (mnemonic):
const seedPhrase = "your seed phrase here...";
lucid.selectWallet.fromSeed(seedPhrase);
If you're integrating with a wallet provider that exposes an API conforming to the WalletApi
interface. This works for any CIP-30 compliant wallet.
// `externalWalletApi` is your wallet provider's API
const walletApi: WalletApi = externalWalletApi;
lucid.selectWallet.fromAPI(walletApi);
This method will create a limited wallet that can still query the address and its UTxOs. You can use it to build transactions that others will sign, as it cannot sign transactions (no private key).
const address = "addr_test...";
const utxos = await lucid.utxosAt(address);
lucid.selectWallet.fromAddress(address, utxos);
Transactions built with an address-only wallet will need to be signed by a wallet with the actual private keys before they can be submitted.