Icon LinkCreating a wallet from a private key

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

	import { Wallet, WalletLocked, WalletUnlocked } from 'fuels';
 
	// use the `generate` helper to make an Unlocked Wallet
	const myWallet: WalletUnlocked = Wallet.generate();
 
	// or use an Address to create a wallet
	const someWallet: WalletLocked = Wallet.fromAddress(myWallet.address);

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

	// unlock an existing wallet
	let unlockedWallet: WalletUnlocked = lockedWallet.unlock(PRIVATE_KEY);
	// or directly from a private key
	unlockedWallet = Wallet.fromPrivateKey(PRIVATE_KEY);

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

	const signer = new Signer(PRIVATE_KEY);
	// validate address
	expect(wallet.address).toEqual(signer.address);

Was this page helpful?