Skip to main content
Create your Farcaster account programmatically and publish your first message. The example shows you how to:
  • Make onchain transactions to create an account
  • Rent a storage unit so you can publish messages
  • Add signer key to sign messages
  • Acquire an fname for your account
  • Create, sign and publish messages
This example can be checked out as a fully functional repository here.

Requirements

  • Write access to a node (either your own, or a 3rd party one)
  • An ETH wallet with about ~10$ USD of ETH bridged to Optimism
  • An ETH RPC URL for OP Mainnet (e.g. via Alchemy, Infura or QuickNode).
See running a node for more information on how to set up a node.

Custody address vs signer

In order to register an account and send messages, you need 2 pairs of keys:
  • Custody: This is the ETH account which funds the initial id registration and storage. You need ~10USDinthisaccount.YoucanuseanyETHaddressaslongasthe10 USD in this account. You can use any ETH address as long as the 10 required is transferred via OP mainnet. The private key will be used to sign any signer requests and fname registrations. The person registering should always hold this private key.
  • Signer: This is a keypair registered with the key registry that’s used to sign messages a user publishes to the Farcaster network. If an app is publishing on behalf of a user, the app will hold the private key for this keypair.

1. Set up constants

2. Register and pay for storage

Create a function to register an FID and pay for storage. This function will check if the account already has an FID and return early if so. If you don’t have a funded account you can use, note the address and private key pair that’s logged. Transfer funds to the address and use the same private key as the CUSTODY_PRIVATE_KEY for the next run of the script.

3. Add a signer

Now, we will add a signer to the key registry. Every signer must have a signed metadata field from the fid of the app requesting it. In our case, we will use our own fid. Note, this requires you to sign a message with the private key of the address holding the fid. If this is not possible, register a separate fid for the app first and use that.

4. Register an fname

Now that the onchain actions are complete, let’s register an fname using the farcaster offchain fname registry. Registering an fname requires a signature from the custody address of the fid.
Note that this only associates the name to our fid, we still need to set it as our username.

5. Write to Snapchain

Finally, we’re now ready to submit messages. First, we shall set the fname as our username. And then post a cast.
Now, you can view your profile on any farcaster client. To see it on Warpcast, visit https://warpcast.com/@<fname>