Build a Hello World (TypeScript)
Prerequisites
Step 1: Create a Bun Project
mkdir hello-world-ml
cd hello-world-ml
bun init -ybun add nostr-tools @solana/web3.jsStep 2: Write the Subscriber Code
// subscriber.ts
import { Relay } from "nostr-tools/relay";
const RELAY_URL = "wss://dev-relay.dephy.dev";
async function main() {
const relay = await Relay.connect(RELAY_URL);
console.log("Subscribed events on", RELAY_URL);
relay.subscribe(
[
{
kinds: [1573],
since: Math.floor(Date.now() / 1000),
"#s": ["hello_session"],
"#p": ["receiver_pubkey"],
},
],
{
onevent: async (event) => {
console.log("Received:", event.content);
},
}
);
}
main().catch(console.error);
Step 3: Write the Publisher Code
Step 4: Run the "Hello World" Example
Next, Enhance the Functionality with Solana Airdrop
Step 5: Update the Publisher
Step 6: Update the Subscriber
Step 7: Run the Enhanced Example
Next Steps
Last updated

