Skip to main content
Create your Farcaster account programmatically and publish your first “Hello World” message. The example shows you how to:
  • Make onchain transactions to create an account
  • Rent a storage unit so you can publish messages
  • Add an account 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 hub (either your own, or a 3rd party hub)
  • 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).

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.

3. Add an account key

Now, we will add an account key to the key registry. Every account key 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 associated the name to our fid, we still need to set it as our username.

5. Write to the hub

Finally, we’re now ready to submit messages to the hub. 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 Farcaster, visit https://farcaster.com/@<fname>