How to Connect Openclaw to Nostr
Quick Start
Connect your Openclaw AI gateway to the Nostr decentralized social network. This guide walks you through installing the plugin, configuring your keys, and setting up relay connections for seamless bot interactions.
Install the Nostr Plugin
The Nostr integration is an optional plugin and is disabled by default. You can install it manually using the CLI:
Openclaw plugins install @Openclaw/nostr Alternatively, you can run Openclaw onboard or Openclaw channels add and select Nostr from the list to be prompted to install it on demand.
Configure Your Nostr Settings
You will need to add the nostr channel block to your ~/.Openclaw/Openclaw.json configuration file. It is highly recommended to reference the private key as an environment variable rather than hardcoding it into the file:
{ "channels": { "nostr": { "privateKey": "${NOSTR_PRIVATE_KEY}", "relays": ["wss://relay.damus.io", "wss://nos.lol"], "dmPolicy": "pairing" } } } Note: Openclaw will default to using wss://relay.damus.io and wss://nos.lol if you omit the relays array, but you can explicitly specify 2-3 relays of your choosing for redundancy.
If you're new to Openclaw channel configuration, you might also want to read about Twitch Integration for another messaging platform setup.
Environment Variables
For better security, set your Nostr private key as an environment variable:
export NOSTR_PRIVATE_KEY="nsec1..." Working Example
Here's what a complete configuration looks like with multiple relays and pairing policy:
{ "channels": { "nostr": { "enabled": true, "privateKey": "${NOSTR_PRIVATE_KEY}", "relays": [ "wss://relay.damus.io", "wss://nos.lol", "wss://relay.nostr.band" ], "dmPolicy": "pairing" } } } For more advanced deployment options, check out our guide on Fly.io Deployment to host your gateway in the cloud.
Restart and Verify
After configuration, restart your Openclaw gateway:
Openclaw gateway restart Your bot will now connect to the specified Nostr relays and can receive direct messages based on your configured policy.
Troubleshooting & Best Practices
- Key Security: Never commit your nsec private key to version control. Always use environment variables.
- Relay Redundancy: Configure at least 2-3 relays to ensure message delivery if one relay goes offline.
- DM Policy: The pairing policy requires users to initiate contact first, preventing spam.
- Connection Issues: If your bot doesn't connect, verify relay URLs are correct and accessible from your network.
- Key Format: Use nsec-encoded private keys. Openclaw handles the key conversion internally.