หมายถึง software ไปลงใช้เองหรือแบบที่เปิดสาธารณะหรอครับ
ฝั่งนี้มี relay.siamdev.cc ของพี่ตี๋ ใช้ strfry https://github.com/hoytech/strfry
และ local.siamdev.cc ที่ใช้ต่อ tunnel มาเข้า nostr-relay-tray ใน laptop ผมครับ
หมายถึง software ไปลงใช้เองหรือแบบที่เปิดสาธารณะหรอครับ
ฝั่งนี้มี relay.siamdev.cc ของพี่ตี๋ ใช้ strfry https://github.com/hoytech/strfry
และ local.siamdev.cc ที่ใช้ต่อ tunnel มาเข้า nostr-relay-tray ใน laptop ผมครับ
ไม่แน่ใจผมเข้าใจอะไรผิดไหม ผมอยากประกาศ Event ไปยัง relay เพื่อเก็บข้อมูลบางอย่าง ตอนนี้ผมเก็บข้อมูลไว้บน firebase เลยอยากเปลี่ยนมาใช้แบบประกาศ event บน relay ดู
อันนี้คือตัวอย่างโค้ด
import {
relayInit,
getEventHash,
getSignature,
finalizeEvent,
nip19,
} from 'nostr-tools';
// 👤 กรอกจาก user
const username = 'satoshi';
const npub = 'npub1...'; // จากฟอร์มของคุณ
// 🧠 แปลง npub → pubkey
const { data: pubkey } = nip19.decode(npub);
// ✍️ สร้าง event
const event = {
kind: 30078,
pubkey,
created_at: Math.floor(Date.now() / 1000),
tags: [['username', username]],
content: 'Lucky draw registration!',
};
// 🔐 เซ็นด้วย private key ของ user (nsec)
const nsec = 'nsec1...'; // สมมติว่า user ลงชื่อด้วย nsec (อาจใช้ extension/extension signer ได้)
const { data: sk } = nip19.decode(nsec);
event.id = getEventHash(event);
event.sig = getSignature(event, sk);
// 📡 ส่งไปยัง relay
const relay = relayInit('wss://relay.damus.io');
await relay.connect();
let pub = relay.publish(event);
pub.on('ok', () => {
console.log('✅ Event published successfully');
});
pub.on('failed', reason => {
console.error('❌ Failed to publish:', reason);
});
ถ้ากำลังพัฒนาผมคิดว่าหา local relay ซัดตัวมา deploy ผ่าน docker ก็ได้ แล้วใช้ ws://localhost:
พอใช้จริงค่อยดึง relay list จากเจ้าของ npub มาใช้แทนจะง่ายกว่าครับ