PHP code example of barechain / rlp

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

    

barechain / rlp example snippets


use Barechain\RLP\RLP;

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

// to string, encoding: ascii utf8 hex
$encodedBuffer->toString($encoding);

use Barechain\RLP\RLP;

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

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

// show dog
echo $decodedArray[0]->toString('utf8');

use Barechain\RLP\RLP;

$rlp = new RLP;
$encodedBuffer = $rlp->encode(['barechain', 'ethereum', 'solidity']);
$encodedString = $encodedBuffer;


use Barechain\RLP\RLP;

$rlp = new RLP;
$encodedBuffer = $rlp->encode(['barechain', 'ethereum', 'solidity']);
$encodedString = $encodedBuffer;
$decodedArray = $rlp->decode('0x' . $encodedString);

// echo barechain
echo $decodedArray[0]->toString('utf8');

// echo ethereum
echo $decodedArray[1]->toString('utf8');

// echo solidity
echo $decodedArray[2]->toString('utf8');