web3p/ethereum-wallet

PHP的以太坊钱包库。

0.1.0 2023-04-28 01:58 UTC

This package is auto-updated.

Last update: 2024-08-28 05:38:24 UTC


README

PHP codecov Licensed under the MIT License

以太坊钱包。

安装

composer require web3p/ethereum-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;

从助记词恢复钱包

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

设置不同的助记词词表,默认为英语。

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;

generate

返回给定助记词长度的钱包。

generate(int $mnemonicLength)

mnemonicLength - 整数。

示例
  • 使用12个助记词生成新钱包。
use Web3p\EthereumWallet\Wallet;

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

fromMnemonic

返回从助记词恢复的钱包。

fromMnemonic(string $mnemonic)

mnemonic - 字符串。

示例
  • 从钱包恢复。
use Web3p\EthereumWallet\Wallet;

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

许可证

MIT