Ethereum wallet.
composer require web3p/ethereum-wallet
Generate a new wallet:
use Web3p\EthereumWallet\Wallet;
$wallet = new Wallet();
$mnemonicLength = 15;
$wallet->generate($mnemonicLength);
// $wallet->address;
// danger zone, if the data was leaked, money would be stolen
// $wallet->privateKey;
// $wallet->mnemonic;
Recover wallet from mnemonic:
use Web3p\EthereumWallet\Wallet;
$wallet = new Wallet();
$mnemonic = '..........';
$wallet->fromMnemonic($mnemonic);
// $wallet->address;
// danger zone, if the data was leaked, money would be stolen
// $wallet->privateKey;
// $wallet->mnemonic;
Set different mnemonic wordlist, the default is english.
setWordlist(WordList $wordlist)
wordList - \BitWasp\Bitcoin\Mnemonic\WordList
use Web3p\EthereumWallet\Wallet;
use Web3p\EthereumWallet\Wordlist\BIP39ChineseTraditionalWordList;
$wallet = new Wallet();
$zh_TW_wordlist = new BIP39ChineseTraditionalWordList;
$wallet->wordlist = $zh_TW_wordlist;
Returns a new wallet for the given mnemonic length.
generate(int $mnemonicLength)
mnemonicLength - integer.
- Generate a new wallet with 12 mnemonic.
use Web3p\EthereumWallet\Wallet;
$wallet = new Wallet();
$wallet->generate(12);
Returns a wallet recover from the mnemonic.
fromMnemonic(string $mnemonic)
mnemonic - string.
- Recover from a wallet.
use Web3p\EthereumWallet\Wallet;
$wallet = new Wallet();
$mnemonic = '..........';
$wallet->fromMnemonic($mnemonic);
MIT