PHP code example of arweave / arweave-sdk

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

    

arweave / arweave-sdk example snippets




$arweave = new \Arweave\SDK\Arweave('http', '209.97.142.169', 1984);

$jwk = json_decode(file_get_contents('jwk.json'), true);

$wallet =  new \Arweave\SDK\Support\Wallet($jwk);

$transaction = $arweave->createTransaction($wallet, [
    'data' => '<html><head><title>Some page</title></head></html>',
    'tags' => [
        'Content-Type' => 'text/html'
    ]
]);

printf('Your transaction ID is %s', $transaction->getAttribute('id'));


// commit() sends the transaction to the network, once sent this can't be undone.
$arweave->api()->commit($transaction);

$arweave = new \Arweave\SDK\Arweave('http', '209.97.142.169', 1984);

$arweave->api()->getTransactionData('mvscO3JBlwweOnfkkHpc3fINQ6cUtn_g5aFY9af5TfQ')

$arweave = new \Arweave\SDK\Arweave('http', '209.97.142.169', 1984);

$arweave->api()->getTransaction('mvscO3JBlwweOnfkkHpc3fINQ6cUtn_g5aFY9af5TfQ');

object(Arweave\SDK\Support\Transaction)#23 (1) {
  ["attributes":protected]=>
  array(10) {
    ["id"]=> string(43) "mvscO3JBlwweOnf..."
    ["last_tx"]=> string(43) "3MFrfH0-HI9GeMf..."
    ["owner"]=> string(683) "1Q7Rfgt23rfUDp..."
    ["target"]=> string(0) ""
    ["quantity"]=> string(1) "0"
    ["data"]=> string(60) "eyJib2R5IjoiVGVz..."
    ["reward"]=> string(10) "1825892857"
    ["signature"]=> string(683) "BUmdaf4rzlyT_3..."
    ["tags"]=> array(0) {}
  }
}

$data = $arweave->api()->getTransactionData($transaction_id);
//string(45) "{"body":"Test body","subject":"Test subject"}"

$transaction = $arweave->api()->getTransaction($transaction_id);

$encoded_data = $transaction->getAttribute('data');
//string(60) "eyJib2R5IjoiVGVzdCBib2R5Iiwic3ViamVjdCI6IlRlc3Qgc3ViamVjdCJ9"

$original_data = base64_decode(\Arweave\SDK\Support\Helpers::base64urlDecode($encoded_data));
//string(45) "{"body":"Test body","subject":"Test subject"}"

$transactionIds = $arweave->api()->arql([
    'op' => 'equals',
    'expr1' => 'App-Name',
    'expr2' => 'arweaveapps'
]);

// array(31) {
//   [0]=>
//   string(43) "NXg2OaRRygb7RJZFbkcEYlS2LNNfsqxxobzUqz7ELnc"
//   [1]=>
//   string(43) "i3_aC8xIO_4TpMqp5sR4WVUwbA1p2sPCu11cLVKN89U
// ...


$jwk = json_decode(file_get_contents('jwk.json'), true);

$wallet =  new \Arweave\SDK\Support\Wallet($jwk);`