Skip to content

ID Gateway

The ID Gateway registers new Farcaster IDs and adds them to the Id Registry.

If you want to create a new Farcaster ID, use the ID Gateway.

Read

price

Get the price in wei to register an fid. This includes the price of 1 storage unit. Use the extraStorage parameter to include extra storage units in the total price.

ParametertypeDescription
extraStorageuint256 (optional)The number of additional storage units

nonces

Get the next unused nonce for an address. Used for generating an EIP-712 Register signature for registerFor.

ParametertypeDescription
owneraddressAddress to get the nonce for

Write

register

Register a new fid to the caller and pay for storage. The caller must not already own an fid.

ParametertypeDescription
msg.valueweiAmount to pay for registration
recoveryaddressRecovery address for the new fid
extraStorageuint256 (optional)Number of additional storage units to rent

registerFor

Register a new fid to a specific address and pay for storage. The receiving address must sign an EIP-712 Register message approving the registration. The receiver must not already own an fid.

ParametertypeDescription
msg.valueweiAmount to pay for registration
toaddressThe address to register the fid to
recoveryaddressRecovery address for the new fid
deadlineuint256Signature expiration timestamp
sigbytesEIP-712 Register signature from the to address
extraStorageuint256 (optional)Additional storage units

Register signature

To register an fid on behalf of another account, you must provide an EIP-712 typed signature from the receiving address in the following format:

Register(address to,address recovery,uint256 nonce,uint256 deadline)

ParametertypeDescription
toaddressAddress to register the fid to. The typed message must be signed by this address.
recoveryaddressRecovery address for the new fid
nonceuint256Current nonce of the to address
deadlineuint256Signature expiration timestamp
ts
import { ViemWalletEip712Signer } from '@farcaster/hub-web';
import { walletClient, account } from './clients.ts';
import { readNonce, getDeadline } from './helpers.ts';

const nonce = await readNonce();
const deadline = getDeadline();

const eip712Signer = new ViemWalletEip712Signer(walletClient);
const signature = await eip712signer.signRegister({
  to: account,
  recovery: '0x00000000FcB080a4D6c39a9354dA9EB9bC104cd7',
  nonce,
  deadline,
});
ts
import { ID_GATEWAY_EIP_712_TYPES } from '@farcaster/hub-web';
import { walletClient, account } from './clients.ts';
import { readNonce, getDeadline } from './helpers.ts';

const nonce = await readNonce();
const deadline = getDeadline();

const signature = await walletClient.signTypedData({
  account,
  ...ID_GATEWAY_EIP_712_TYPES,
  primaryType: 'Register',
  message: {
    to: account,
    recovery: '0x00000000FcB080a4D6c39a9354dA9EB9bC104cd7',
    nonce,
    deadline,
  },
});
ts
import { ID_GATEWAY_ADDRESS, idGatewayABI } from '@farcaster/hub-web';
import { publicClient, account } from './clients.ts';

export const getDeadline = () => {
  const now = Math.floor(Date.now() / 1000);
  const oneHour = 60 * 60;
  return now + oneHour;
};

export const readNonce = async () => {
  return await publicClient.readContract({
    address: ID_GATEWAY_ADDRESS,
    abi: idGatewayABI,
    functionName: 'nonces',
    args: [account],
  });
};
ts
import { createWalletClient, createPublicClient, custom, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { optimism } from 'viem/chains';

export const publicClient = createPublicClient({
  chain: optimism,
  transport: http(),
});

export const walletClient = createWalletClient({
  chain: optimism,
  transport: custom(window.ethereum),
});

// JSON-RPC Account
export const [account] = await walletClient.getAddresses();

// Local Account
export const account = privateKeyToAccount('0x...');

Errors

ErrorSelectorDescription
InvalidSignature8baa579fThe provided signature is invalid. It may be incorrectly formatted, or signed by the wrong address.
SignatureExpired0819bdcdThe provided signature has expired. Collect a new signature from the signer with a later deadline timestamp.

Source

IdGateway.sol