bobicloudvision / ethereum-wallet
Ethereum wallet library in PHP.
0.1
2023-08-10 14:28 UTC
Requires
- php: ^7.1 | ^8.0
- bitwasp/bitcoin: *
- web3p/ethereum-util: *
Requires (Dev)
- phpunit/phpunit: ~7 | ~8.0
This package is auto-updated.
Last update: 2025-01-10 17:19:58 UTC
README
Ethereum wallet.
Install
composer require bobicloudvision/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