Skip to content

Creating a wallet from a private key

A new wallet with a randomly generated private key can be created by supplying Wallet.generate.

ts
import type { WalletLocked, WalletUnlocked } from 'fuels';
import { Wallet } from 'fuels';

// We can use the `generate` to create a new unlocked wallet.
const myWallet: WalletUnlocked = Wallet.generate({ provider });

// or use an Address to create a wallet
const someWallet: WalletLocked = Wallet.fromAddress(myWallet.address, provider);
See code in context

Alternatively, you can create a wallet from a Private Key:

ts
// unlock an existing unlocked wallet
let unlockedWallet: WalletUnlocked = lockedWallet.unlock(PRIVATE_KEY);
// or directly from a private key
unlockedWallet = Wallet.fromPrivateKey(PRIVATE_KEY, provider);
See code in context

You can obtain an address to a private key using the Signer package

ts
const signer = new Signer(PRIVATE_KEY);
See code in context