-
@ nostr_cn_dev
2025-04-12 07:34:06Get started
A step-by-step guide to getting started with Nostr.
这里主要面对开发者,下面会有一些例子。
Understanding keys
Each Nostr account is based on a public/private key pair. A simple way to think about this is that your public key is your username and your private key is your password, with one major caveat. Unlike a password, your private key cannot be reset if lost.
The public key is generally presented as a string with the prefix npub and the private key with the prefix nsec. Make sure you store you private key somewhere safe, like a password manager.
nodejs example
使用 nostr-tools 开始第一个例子
https://github.com/nbd-wtf/nostr-tools
```
npm
npm install --save nostr-tools
jsr
npx jsr add @nostr/tools ```
Generating a private key and a public key
```js import { generateSecretKey, getPublicKey } from 'nostr-tools/pure'
let sk = generateSecretKey() //
sk
is a Uint8Array let pk = getPublicKey(sk) //pk
is a hex string ```To get the secret key in hex format, use ```js import { bytesToHex, hexToBytes } from '@noble/hashes/utils' // already an installed dependency
let skHex = bytesToHex(sk) let backToBytes = hexToBytes(skHex) ```
这样你就得到了你的 nostr账户了,完全是程序生成的。
任何人都可以生成,javascript,python ,rust 等各种语言都可以
git clone https://github.com/duozhutuan/nostrclient
python from nostrclient.key import PrivateKey pkey = PrivateKey() print("Your public key: ",pkey.public_key) print("Your public key bech32: ",pkey.public_key.bech32())
Keeping keys safe
If you are using Nostr on a web browser it is probably a good idea to install an extension like Connect, nos2x or Alby, then input your secret key there (or it will generate a secret key for you). From there you will be able to use all web apps very easily with no worries. For the paranoid, keeping your key on a hardware device is also an option.
If you are on Android, installing Amber is the safest way to use Nostr without having to paste your key directly into apps.
Otherwise it's probably safe to paste your nsec into well-established and security-minded apps such as Damus, so don't worry too much.
Let's do this!
Now that you know what it takes, just pick a client to start using Nostr!
Finding people to follow If you know someone that is on Nostr, start by following them, then look at whom they are following and whom they are interacting with, and sooner rather than later you'll have a bunch of followers and a community for yourself inside Nostr.
Otherwise, you can always take a look at trending posts and people and get people from there.