PHP code example of kornrunner / rlp

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

    

kornrunner / rlp example snippets


use kornrunner\RLP\RLP;

$rlp = new RLP;
// c483646f67
$encoded = $rlp->encode(['dog']);

// 83646f67
$encoded = $rlp->encode('dog');

use kornrunner\RLP\RLP;
use kornrunner\RLP\Types\Str;

$rlp = new RLP;
$encoded = $rlp->encode(['dog']);

// only accept 0x prefixed hex string
$decoded = $rlp->decode('0x' . $encoded);

// show 646f67
echo $decoded[0];

// show dog
echo hex2bin($decoded[0]);

// or you can
echo Str::decodeHex($decoded[0]);

use kornrunner\RLP\RLP;

$rlp = new RLP;
$encoded = $rlp->encode(['kornrunner', 'ethereum', 'solidity']);

use kornrunner\RLP\RLP;
use kornrunner\RLP\Types\Str;

$rlp = new RLP;
$encoded = $rlp->encode(['kornrunner', 'ethereum', 'solidity']);
$decoded = $rlp->decode('0x' . $encoded);

// echo kornrunner
echo hex2bin($decoded[0]);

// echo ethereum
echo hex2bin($decoded[1]);

// echo solidity
echo hex2bin($decoded[2]);

// or you can
echo Str::decodeHex($decoded[0]);
echo Str::decodeHex($decoded[1]);
echo Str::decodeHex($decoded[2]);