Skip to content


A PHP helper library for Nostr

Empower your 🐘 PHP project with Nostr.


Get started

Add the nostr-php package to your PHP project with Composer

composer require nostrverse/nostr-php

Here is an example how to create and publish an event to a relay:


require __DIR__ . '/vendor/autoload.php';

use swentel\nostr\Event\Event;
use swentel\nostr\Key\Key;
use swentel\nostr\Message\EventMessage;
use swentel\nostr\Relay\Relay;
use swentel\nostr\Sign\Sign;

function send($message) {  
  try {        
        $key = new Key();
        $private_key = $key->generatePrivateKey(); // this will generate a private key
        $private_key_hex = $key->convertToHex($private_key);
        $public_key = $key->getPublicKey($private_key_hex);
        $relayUrl = 'wss://';
        $note = new Event();
        $note->addTag(['p', $public_key]);
        $note->addTag(['r', $relayUrl]);
        $signer = new Sign();
        $signer->signEvent($note, $private_key);        
        $eventMessage = new EventMessage($note);
        $relay = new Relay($relayUrl);  
        $result = $relay->send();
        if ($result->isSuccess()) {
            print "The event has been sent to Nostr!\n";
        } else {
            print 'Something went wrong: ' . $result->message() . "\n";
    } catch (Exception $e) {
        print 'Exception error: ' . $e->getMessage() . "\n";

$message = 'Hello world ' . date('Y-m-d H:i:s');

For more examples please check this README.

Released under the MIT License. Supported by OpenSats.
Source Code