PHP code example of activeledger / sdk

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

    

activeledger / sdk example snippets






// Setup the connection object to use localhost over http unencrypted
$connection = new activeledger\sdk\Connection("http", "127.0.0.1", 5260, false);

// Use localhost but encrypt transactions
$connection = new activeledger\sdk\Connection("http", "127.0.0.1", 5260, true);



// Generate Elliptic Key
$identity = activeledger\sdk\Key::generateKeyIdentity();

// Generate RSA Key
$identity = activeledger\sdk\Key::generateKeyIdentity("rsa");



// Create Connection
$connection = new activeledger\sdk\Connection("http", "127.0.0.1", 5260, false);

// Generate Key
$identity = activeledger\sdk\Key::generateKeyIdentity();

try {
    // Onboard Key
    $stream = $identity->onBoard($connection);
}catch(Exception $error) {
    // Manage any exceptions such as consensus problem or transport errors
    die($error->getMessage());
}



// Generate Key
$identity = activeledger\sdk\Key::generateKeyIdentity();

// Store object as a safe string
$export = base64_encode(serialize($identity));



// Restore KeyIdentity Object from the exported safe string
$identity = serialize(base64_decode($export))



// Generate Activeledger Transaction
$transaction = activeledger\sdk\Transaction::build(
    "Contract Stream / Label",
    "Namespace",
    // Input Streams (Requires Signatures)
    array("Identity Stream" => array()),
    // Outputs
    array("Outputs: Identity Stream" => array()),
    // Read Only Streams
    array("Reads : Label" => "Idenity Stream")
);



// Create Connection
$connection = new activeledger\sdk\Connection("http", "127.0.0.1", 5260, false);

// Generate Key
$identity = activeledger\sdk\Key::generateKeyIdentity();

try {
    // Onboard Key
    $stream = $identity->onBoard($connection);

    // Generate Activeledger Transaction
    $transaction = activeledger\sdk\Transaction::build(
        "0000482232bcca98e3f2b375e6209400e185fae26efad7812268d7d66b321131",
        "example-namespace",
        // Input Streams (Requires Signatures)
        array($stream => array("text" => "Hello World"))
    );

    // Get signed version of this transaction
    $signedTx = $identity->sign($transaction)

    // Submit
    $response = $connection->send($signedTx);

    // Response object will contain the streams property.
    $response->streams->new; // Contains created Activity Streams
    $response->streams->updated; // Contains updated Activity Streams

}catch(Exception $error) {
    // Manage any exceptions such as consensus problem or transport errors
    die($error->getMessage());
}