Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public final class Wallet

  1. Object
  2. Wallet

One wallet across chains, over a Signer. It knows the standard derivation paths, so the addresses it answers are the ones other wallets restore from the same mnemonic:

  • EVM: m/44'/60'/account'/0/index, as MetaMask and Ledger derive
  • Bitcoin: m/purpose'/coin'/account'/change/index with purpose 44 (P2PKH), 49 (P2SH-P2WPKH), 84 (P2WPKH) or 86 (P2TR), and the coin type of the network
  • Solana: m/44'/501'/account'/0', as Phantom and Solflare derive
String words = Mnemonic.generate(128);
Wallet w = Wallet.fromMnemonic(words, "");
EvmAddress eth = w.getEvmAddress(0, 0);
BitcoinAddress btc = w.getBitcoinAddress(BitcoinNetwork.MAINNET, Wallet.BIP84, 0, 0, 0);
SolanaAddress sol = w.getSolanaAddress(0);
EvmTransaction tx = EvmTransaction.eip1559(1, 0, UInt256.parseUnits("1", 9),
        UInt256.parseUnits("30", 9), 21000, eth, UInt256.ZERO, null);
EvmTransaction signed = w.signEvmTransaction(tx, Wallet.evmPath(0, 0));

Fields

public static final int BIP44 = 44BIP-44 legacy P2PKH accounts.
public static final int BIP49 = 49BIP-49 P2SH-wrapped SegWit accounts.
public static final int BIP84 = 84BIP-84 native SegWit accounts.
public static final int BIP86 = 86BIP-86 Taproot accounts.

Constructors

public Wallet(Signer signer)A wallet over a signer.

Methods

public static Wallet fromMnemonic(String mnemonic, String passphrase)A wallet over an in-memory SeedSigner for a mnemonic.
public Signer getSigner()The signer.
public static DerivationPath evmPath(int account, int index)m/44'/60'/account'/0/index.
public EvmAddress getEvmAddress(int account, int index)The EVM address at an account and index.
public EvmAddress getEvmAddress(DerivationPath path)The EVM address at a path.
public EvmTransaction signEvmTransaction(EvmTransaction tx, DerivationPath path)Signs a transaction with the key at a path, answering the signed transaction.
public byte[] personalSign(byte[] message, DerivationPath path)An EIP-191 personal_sign signature, r || s || v with v 27 or 28.
public byte[] personalSign(String message, DerivationPath path)An EIP-191 signature of UTF-8 text.
public byte[] signTypedData(TypedData data, DerivationPath path)An EIP-712 signature, r || s || v with v 27 or 28.
public static DerivationPath bitcoinPath(BitcoinNetwork network, int purpose, int account, int change, int index)m/purpose'/coin'/account'/change/index for a network.
public BitcoinAddress getBitcoinAddress(BitcoinNetwork network, int purpose, int account, int change, int index)The address of the output type a purpose implies, at a path under it.
public BitcoinKey getBitcoinKey(DerivationPath path)The key at a path, for Psbt.sign(int, BitcoinKey); it signs through the signer.
public int signPsbt(Psbt psbt)Signs every PSBT input whose recorded BIP-32 origin is this wallet’s master, answering how many inputs were signed.
public static DerivationPath solanaPath(int account)m/44'/501'/account'/0'.
public SolanaAddress getSolanaAddress(int account)The Solana address of an account.
public SolanaAddress getSolanaAddress(DerivationPath path)The Solana address at a path.
public void signSolanaTransaction(SolanaTransaction tx, DerivationPath path)Adds the signature of the key at a path to a transaction it must sign.
public void signSolanaTransaction(SolanaTransaction tx, int account)Adds the signature of an account’s key.

Inherited methods

Field details

BIP44

public static final int BIP44 = 44
BIP-44 legacy P2PKH accounts.

BIP49

public static final int BIP49 = 49
BIP-49 P2SH-wrapped SegWit accounts.

BIP84

public static final int BIP84 = 84
BIP-84 native SegWit accounts.

BIP86

public static final int BIP86 = 86
BIP-86 Taproot accounts.

Constructor details

Wallet

public Wallet(Signer signer)
A wallet over a signer.

Method details

fromMnemonic

public static Wallet fromMnemonic(String mnemonic, String passphrase)
A wallet over an in-memory SeedSigner for a mnemonic.

getSigner

public Signer getSigner()
The signer.

evmPath

public static DerivationPath evmPath(int account, int index)
m/44'/60'/account'/0/index.

getEvmAddress

public EvmAddress getEvmAddress(int account, int index)
The EVM address at an account and index.

getEvmAddress

public EvmAddress getEvmAddress(DerivationPath path)
The EVM address at a path.

signEvmTransaction

public EvmTransaction signEvmTransaction(EvmTransaction tx, DerivationPath path)
Signs a transaction with the key at a path, answering the signed transaction.

personalSign

public byte[] personalSign(byte[] message, DerivationPath path)
An EIP-191 personal_sign signature, r || s || v with v 27 or 28.

personalSign

public byte[] personalSign(String message, DerivationPath path)
An EIP-191 signature of UTF-8 text.

signTypedData

public byte[] signTypedData(TypedData data, DerivationPath path)
An EIP-712 signature, r || s || v with v 27 or 28.

bitcoinPath

public static DerivationPath bitcoinPath(BitcoinNetwork network, int purpose, int account, int change, int index)
m/purpose'/coin'/account'/change/index for a network.

getBitcoinAddress

public BitcoinAddress getBitcoinAddress(BitcoinNetwork network, int purpose, int account, int change, int index)
The address of the output type a purpose implies, at a path under it.

Throws

IllegalArgumentException
for a purpose other than 44, 49, 84 or 86

getBitcoinKey

public BitcoinKey getBitcoinKey(DerivationPath path)
The key at a path, for Psbt.sign(int, BitcoinKey); it signs through the signer.

signPsbt

public int signPsbt(Psbt psbt)
Signs every PSBT input whose recorded BIP-32 origin is this wallet’s master, answering how many inputs were signed. The PSBT’s creator records the origins (Psbt.addBip32Derivation, Psbt.addTapBip32Derivation), as every wallet does.

solanaPath

public static DerivationPath solanaPath(int account)
m/44'/501'/account'/0'.

getSolanaAddress

public SolanaAddress getSolanaAddress(int account)
The Solana address of an account.

getSolanaAddress

public SolanaAddress getSolanaAddress(DerivationPath path)
The Solana address at a path.

signSolanaTransaction

public void signSolanaTransaction(SolanaTransaction tx, DerivationPath path)
Adds the signature of the key at a path to a transaction it must sign.

signSolanaTransaction

public void signSolanaTransaction(SolanaTransaction tx, int account)
Adds the signature of an account’s key.