Skip to content

Commit

Permalink
update readme example.
Browse files Browse the repository at this point in the history
fixes #337
  • Loading branch information
fiatjaf committed Dec 27, 2023
1 parent 75df474 commit da51418
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,28 @@ const sub = relay.subscribe([
let sk = generateSecretKey()
let pk = getPublicKey(sk)

let sub = relay.sub([
relay.sub([
{
kinds: [1],
authors: [pk],
},
])

sub.on('event', event => {
console.log('got event:', event)
], {
onevent(event) {
console.log('got event:', event)
}
})

let event = {
let eventTemplate = {
kind: 1,
created_at: Math.floor(Date.now() / 1000),
tags: [],
content: 'hello world',
}

// this assigns the pubkey, calculates the event id and signs the event in a single step
const signedEvent = finalizeEvent(event, sk)
const signedEvent = finalizeEvent(eventTemplate, sk)
await relay.publish(signedEvent)

let events = await relay.list([{ kinds: [0, 1] }])
let event = await relay.get({
ids: ['44e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245'],
})

relay.close()
```

Expand Down

0 comments on commit da51418

Please sign in to comment.