PHP code example of blocker / bip39

1. Go to this page and download the library: Download blocker/bip39 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/ */

    

blocker / bip39 example snippets




// aliases.
use Blocker\Bip39\Util\Entropy;

$entropy = new Entropy($dataInHexadecimal);



// aliases.
use Blocker\Bip39\Util\Entropy;

// the parameter here is the size, in bits, of the random data to be generated.
// values can be between 128 and 256, and must be multiples of 32.
$entropy = Entropy::random(128);



// aliases.
use Blocker\Bip39\Bip39;
use Blocker\Bip39\Util\Entropy;

// a word sequence provided by the user.
$some128bitValueAlreadyEncoded = 'walnut antenna forward shuffle invest legal confirm polar hope timber pear cover';

// create a bip39 instance.
$bip39 = new Bip39('en'); 

// decode the given word list into an entropy instance.
$entropy = $bip39->decode($some128bitValueAlreadyEncoded);

// decode the provided word sequence into a hexadecimal encoded entropy.
echo (string) $entropy; // "f6c1396f63b75efecbbd3b6d7c468818"


// aliases.
use Blocker\Bip39\Bip39;
use Blocker\Bip39\Util\Entropy;

// some entropy value to be encoded with BIP39.
$previousGeneratedEntropyHex = 'f6c1396f63b75efecbbd3b6d7c468818';

//$some128bitValueAlreadyEncoded = 'walnut antenna forward shuffle invest legal confirm polar hope timber pear cover';

// create a bip39 instance.
$bip39 = new Bip39('en'); 

// create an entropy instance from it's hex representation.
$entropy = new Entropy($previousGeneratedEntropyHex);

echo (string) $bip39->setEntropy($entropy)->encode();
// 'walnut antenna forward shuffle invest legal confirm polar hope timber pear cover'


$bip39 = new Bip39('en');
$bip39 = new Bip39('es');
$bip39 = new Bip39('fr');
// ...