web3p / ethereum-wallet
Ethereum wallet library in PHP.
Installs: 2 225
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 4
Forks: 13
Open Issues: 1
Requires
- php: ^7.1 | ^8.0
- bitwasp/bitcoin: ^1.0
- web3p/ethereum-util: ^0.1
Requires (Dev)
- phpunit/phpunit: ~7 | ~8.0
This package is auto-updated.
Last update: 2024-10-28 05:56:34 UTC
README
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