PHP code example of xiaohuasheng0x1 / bip39-php

1. Go to this page and download the library: Download xiaohuasheng0x1/bip39-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xiaohuasheng0x1 / bip39-php example snippets



declare(strict_types=1);

use \BIP\BIP39;

$mnemonic = BIP39::Generate(12);
var_dump($mnemonic->words);
# array(12) { [0]=> string(6) "barrel" [1]=> string(6) "viable" [2]=> string(6) "become" [3]=> string(4) "kiss" [4]=> string(6) "spider" [5]=> string(8) "business" [6]=> string(4) "wool" [7]=> string(6) "amused" [8]=> string(7) "satoshi" [9]=> string(4) "duty" [10]=> string(4) "girl" [11]=> string(5) "april" }
var_dump($mnemonic->entropy);
# string(32) "12de684fbd6d1a3e3f5041bf68918905" 


declare(strict_types=1);

use \BIP\BIP39;

$mnemonic = BIP39::Entropy("f47f0e5dcf6d1ddf0e70791dafc9ae512130891817769976cd50533021e58a8b");
var_dump($mnemonic->wordsCount); # int(24) 
var_dump($mnemonic->words); # array(24) { [0]=> string(7) "virtual" [1]=> string(4) "wear" [2]=> stri...
var_dump($mnemonic->binaryChunks); # array(24) { [0]=> string(11) "11110100011" [1]=> string(11) "11111000011" [2]=> string(11) "10010...
var_dump($mnemonic->entropy); # string(64) "f47f0e5dcf6d1ddf0e70791dafc9ae512130891817769976cd50533021e58a8b"


declare(strict_types=1);

use \BIP\BIP39;

$mnemonic = BIP39::Words("virtual wear number paddle spike usage degree august buffalo layer high pelican basic duty gate uphold offer reopen favorite please acoustic version clay leader");
var_dump($mnemonic->entropy); # string(64) "f47f0e5dcf6d1ddf0e70791dafc9ae512130891817769976cd50533021e58a8b"


declare(strict_types=1);

use \BIP\BIP39;
use \BIP\Wordlist;

$mnemonic = (new BIP39(12, Wordlist::Spanish())) // 12 words, Spanish language
    ->generateSecureMnemonic(); // Generate mnemonic
    
print implode(" ", $mnemonic->words); # bastón tímido turismo pez pez fideo pellejo persona brinco yoga rasgo diluir
print $mnemonic->entropy; # 1c9cfbc5d93b26b12bcd8c229fdb07a2