Skip to content

Latest commit

 

History

History
109 lines (71 loc) · 2.09 KB

README.md

File metadata and controls

109 lines (71 loc) · 2.09 KB

ethereum-wallet

PHP codecov Licensed under the MIT License

Ethereum wallet.

Install

composer require web3p/ethereum-wallet

Usage

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;

API

Web3p\EthereumWallet\Wallet

setWordlist

Set different mnemonic wordlist, the default is english.

setWordlist(WordList $wordlist)

wordList - \BitWasp\Bitcoin\Mnemonic\WordList

Example
use Web3p\EthereumWallet\Wallet;
use Web3p\EthereumWallet\Wordlist\BIP39ChineseTraditionalWordList;

$wallet = new Wallet();
$zh_TW_wordlist = new BIP39ChineseTraditionalWordList;
$wallet->wordlist = $zh_TW_wordlist;

generate

Returns a new wallet for the given mnemonic length.

generate(int $mnemonicLength)

mnemonicLength - integer.

Example
  • Generate a new wallet with 12 mnemonic.
use Web3p\EthereumWallet\Wallet;

$wallet = new Wallet();
$wallet->generate(12);

fromMnemonic

Returns a wallet recover from the mnemonic.

fromMnemonic(string $mnemonic)

mnemonic - string.

Example
  • Recover from a wallet.
use Web3p\EthereumWallet\Wallet;

$wallet = new Wallet();
$mnemonic = '..........';
$wallet->fromMnemonic($mnemonic);

License

MIT