web3p/ethereum-wallet

Ethereum wallet library in PHP.

0.1.0 2023-04-28 01:58 UTC

This package is auto-updated.

Last update: 2024-06-28 05:19:34 UTC


README

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