Skip to main content
Pre-requisites
  • An Ethereum wallet on OP Mainnet, with sufficient ETH for gas costs.
  • An Ethereum provider URL for OP Mainnet (e.g. via Alchemy, Infura or QuickNode).
You can register a new user using the Bundler contract. To do so, you’ll need to:
  1. Set up Viem clients and @farcaster/hub-web account keys.
  2. Register an app FID if your app does not already have one.
  3. Collect a Register signature from the user.
  4. Create a new account key pair for the user.
  5. Use your app account to create a Signed Key Request.
  6. Collect an Add signature from the user.
  7. Call the Bundler contract to register onchain.

1. Set up clients and account keys

First, set up Viem clients and @farcaster/hub-web account keys. In this example, we’ll use Viem local accounts and account keys, but you can also use ViemWalletEip712Signer to connect to a user’s wallet rather than a local account.

2. Register an app FID

Register an app FID if you don’t already have one. To register an FID, you’ll need to read the price from the ID Gateway, then call the ID Gateway and pay the registration price. You can read back your new FID from the Id Registry contract, or parse it from a Register event. Here, we’ll read it from the registry contract.

3. Collect a Register signature from the user.

Collect an EIP-712 Register signature from the user. In a real world app, you’ll likely collect this signature on your frontend, from the user’s wallet. In a frontend context, you can us a ViemEip712WalletSigner to connect to a browser wallet rather than a local signer.

4. Create a new account keypair

Create a new Ed25519 account keypair for the user. In a real app, ensure you keep the user’s private key secret.

5. Use your app account to create a Signed Key Request

Create a Signed Key Request, signed by your app account. To do so, you can use the getSignedKeyRequestMetadata helper, which generates and signs the Signed Key Request.

6. Collect an Add signature from the user.

Collect an EIP-712 Add signature from the user to authorize adding an account key to their FID.

7. Call the Bundler contract to register onchain.

Call the Key Gateway contract and provide the user’s signature to add the key onchain.

Full code example

See the full code example below for all the steps above.
[@farcaster/hub-web]
See the Bundler reference for more details.