1. Go to this page and download the library: Download swentel/nostr-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/ */
swentel / nostr-php example snippets
use swentel\nostr\Event\Event;
$note = new Event();
$note->setKind(1);
$note->setContent('Hello world!');
$note->setTags([
['e', $relayUrl],
['p', $public_key, $relayUrl],
['r', $relayUrl],
]);
// or use addTag()
$note->addTag(['p', $public_key, $relayUrl]);
use swentel\nostr\Event\Event;
use swentel\nostr\Sign\Sign;
$note = new Event();
$note->setContent('Hello world!');
$note->setKind(1);
$signer = new Sign();
$signer->signEvent($note, $private_key);
use swentel\nostr\Sign\Sign;
use swentel\nostr\Message\EventMessage;
$signer = new Sign();
$signer->signEvent($note, $private_key);
$eventMessage = new EventMessage($note);
$message_string = $eventMessage->generate();
use swentel\nostr\Event\Event;
use swentel\nostr\Message\EventMessage;
use swentel\nostr\Relay\Relay;
$note = new Event();
$note->setContent('Hello world');
$note->setKind(1);
$signer = new Sign();
$signer->signEvent($note, $private_key);
$eventMessage = new EventMessage($note);
$relayUrl = 'wss://nostr-websocket.tld';
$relay = new Relay($relayUrl);
$relay->setMessage($eventMessage);
$result = $relay->send();
$relay1 = new Relay(''wss://nostr-websocket1.tld'');
$relay2 = new Relay(''wss://nostr-websocket2.tld'');
$relay3 = new Relay(''wss://nostr-websocket3.tld'');
$relay4 = new Relay(''wss://nostr-websocket4.tld'');
$relaySet = new RelaySet();
$relaySet->setRelays([$relay1, $relay2, $relay3, $relay4]);
$relaySet->setMessage($eventMessage);
$result = $relay->send();
$subscription = new Subscription();
$subscriptionId = $subscription->setId();
$filter1 = new Filter();
$filter1->setKinds([1, 3]); // You can add multiple kind numbers
$filter1->setLimit(25); // Limit to fetch only a maximum of 25 events
$filters = [$filter1]; // You can add multiple filters.
$requestMessage = new RequestMessage($subscriptionId, $filters);
$relayUrl = 'wss://nostr-websocket.tld';
$relay = new Relay($relayUrl);
$relay->setMessage($requestMessage);
$request = new Request($relay, $requestMessage);
$response = $request->send();