1. Go to this page and download the library: Download suicore/walrus-sdk-php 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/ */
suicore / walrus-sdk-php example snippets
uicore\Walrus\Types\StoreBlobOrQuiltOptions;
use Suicore\Walrus\WalrusClient;
// Set your API endpoints
$publisherUrl = 'https://publisher.walrus-testnet.walrus.space';
$aggregatorUrl = 'https://aggregator.walrus-testnet.walrus.space';
// Instantiate the client
$client = new WalrusClient($publisherUrl, $aggregatorUrl);
// Prepare options for storing a blob
$options = new StoreBlobOrQuiltOptions(epochs: 2);
// Store a text blob
$storeResponse = $client->storeBlob("Hello, Walrus!", $options);
// Check if the blob was newly created
if ($storeResponse->isNewlyCreated()) {
$blobId = $storeResponse->getNewlyCreated()->getBlobObject()->getBlobId();
echo "Blob stored successfully with ID: {$blobId}\n";
} else {
// Handle the already certified case
$blobId = $storeResponse->getAlreadyCertified()->getBlobId();
echo "Blob was already certified with ID: {$blobId}\n";
}
// Retrieve the blob content
$content = $client->getBlob($blobId);
echo "Retrieved content: {$content}\n";
// Save a file as a blob
$file = '/path/to/file.txt';
$options = new StoreBlobOrQuiltOptions(epochs: 2);
$storeResponse = $client->storeBlob(dataOrPath: $file, options: $options, isFile: true);
use Suicore\Walrus\WalrusClient;
use Suicore\Walrus\Types\StoreBlobOrQuiltOptions;
use Suicore\Walrus\Types\QuiltElementFile;
use Suicore\Walrus\Types\QuiltElementFileMetadata;
$client = new WalrusClient($publisherUrl, $aggregatorUrl);
$options = new StoreBlobOrQuiltOptions(epochs: 2);
$files = [
new QuiltElementFile('wal1.jpg', __DIR__ . '/walrus.jpg'),
new QuiltElementFile('wal2.jpg', fopen(__DIR__ . '/walrus.jpg', 'rb')), // Open resource
];
$metadata = [
new QuiltElementFileMetadata('wal1.jpg', (object)['creator' => 'walrus', 'version' => '1.0']),
new QuiltElementFileMetadata('wal2.jpg', (object)['type' => 'logo', 'format' => 'png']),
];
$storeResponse = $client->storeQuilt($files, $options, $metadata);
$files = $storeResponse->getStoredQuiltBlobs()->getQuiltFiles();
foreach ($files as $file) {
echo "Stored patch ID: " . $file->getQuiltPatchId() . "\n";
}
use Suicore\Walrus\Helpers\Aes256Encryptor;
// Encrypt data
$encryptor = new Aes256Encryptor('01234567890123456789012345678901'); // EXAMPLE, USE A DIFFERENT KEY!
$encryptedData = $encryptor->encrypt('Hello, Walrus!');
echo "Encrypted data: {$encryptedData}\n";
// Decrypt data
$decryptedData = $encryptor->decrypt($encryptedData);
echo "Decrypted data: {$decryptedData}\n";
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.