Skip to content

Id Registry

The Id Registry records which fid is associated with which Ethereum address, and manages fid transfers and recoveries.

If you want to read information about an fid, transfer or recover an fid, or manage an fid's recovery address, use the Id Registry.

If you want to register a new fid, use the ID Gateway instead.

Read

idOf

Returns the fid (uint256) owned by an address, or returns zero if the address does not own an fid.

ParametertypeDescription
owneraddressThe address to check for an fid

custodyOf

Returns the custody address (address) that owns a specific fid. Returns the zero address if the fid does not exist.

ParametertypeDescription
fiduint256The fid to find the owner for

recoveryOf

Returns the recovery address (address) of an fid. Returns the zero address if the fid does not exist.

ParametertypeDescription
fiduint256The fid to find the recovery address for

idCounter

Returns the highest registered fid (uint256) so far.

verifyFidSignature

Checks that a message was signed by the current custody address of an fid. Returns a bool.

ParametertypeDescription
custodyAddressaddressThe address to check the signature of
fiduint256The fid associated with the signature
digestbytes32Hashed signed data
sigbytesSignature to check

nonces

Returns the next unused nonce (uint256) for an address. Used for generating EIP-712 signatures.

ParametertypeDescription
owneraddressThe address to get the nonce for

Write

register

Will revert if called directly. Must be called via the ID Gateway.

changeRecoveryAddress

Change the recovery address for the caller's fid.

ParametertypeDescription
recoveryaddressThe new recovery address

transfer

Transfer the caller's fid to a new address. The to address must sign an EIP-712 Transfer message accepting the transfer. The to address must not already own an fid.

ParametertypeDescription
toaddressAddress to transfer the fid to
deadlineuint256Signature deadline
sigbytesEIP-712 Transfer signature from the to address

WARNING

Transferring an fid does not reset its recovery address. To transfer an fid and update its recovery address, call transferAndChangeRecovery. If you are receiving an fid from an untrusted sender, ensure its recovery address is cleared or changed on transfer.

Transfer signature

To transfer an fid to another account, the caller must provide an EIP-712 typed signature from the receiving address in the following format:

Transfer(uint256 fid,address to,uint256 nonce,uint256 deadline)

ParametertypeDescription
fiduint256The fid being transferred
toaddressThe address receiving the fid.
nonceuint256Current nonce of the signer 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.signTransfer({
  fid: 1n,
  to: account,
  nonce,
  deadline,
});
ts
import { ID_REGISTRY_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_REGISTRY_EIP_712_TYPES,
  primaryType: 'Transfer',
  message: {
    fid: 1n,
    to: account,
    nonce,
    deadline,
  },
});
ts
import { ID_REGISTRY_ADDRESS, idRegistryABI } 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_REGISTRY_ADDRESS,
    abi: idRegistryABI,
    functionName: 'nonce',
    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...');

transferAndChangeRecovery

Transfer the fid of the caller to a new address and change the fid's recovery address. This can be used to safely receive an fid transfer from an untrusted address.

The receiving address must sign an EIP-712 TransferAndChangeRecovery message accepting the transfer. The to address must not already own an fid.

ParametertypeDescription
toaddressThe address to transfer the fid to
recoveryaddressThe new recovery address
deadlineuint256Signature deadline
sigbytesEIP-712 TransferAndChangeRecovery signature from the to address

TransferAndChangeRecovery signature

To transfer an fid to another account and change recovery, you must provide an EIP-712 typed signature from the to address in the following format:

TransferAndChangeRecovery(uint256 fid,address to,address recovery,uint256 nonce,uint256 deadline)

ParametertypeDescription
fiduint256The fid being transferred
toaddressThe address receiving the fid
recoveryaddressThe new recovery address
nonceuint256Current nonce of the signer 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.signTransferAndChangeRecovery({
  fid: 1n,
  to: account,
  recovery: '0x00000000FcB080a4D6c39a9354dA9EB9bC104cd7',
  nonce,
  deadline,
});
ts
import { ID_REGISTRY_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_REGISTRY_EIP_712_TYPES,
  primaryType: 'TransferAndChangeRecovery',
  message: {
    fid: 1n,
    to: account,
    recovery: '0x00000000FcB080a4D6c39a9354dA9EB9bC104cd7',
    nonce,
    deadline,
  },
});
ts
import { ID_REGISTRY_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_REGISTRY_ADDRESS,
    abi: idRegistryABI,
    functionName: 'nonce',
    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...');

recover

Transfer an fid to a new address if caller is the recovery address. The to address must sign an EIP-712 Transfer message accepting the transfer.

The to address must not already own an fid.

ParametertypeDescription
fromaddressThe address to transfer the fid from
toaddressThe address to transfer the fid to
deadlineuint256Signature deadline
sigbytesEIP-712 Transfer signature from the to address

changeRecoveryAddressFor

Change the recovery address of an fid on behalf of the owner by providing a signature. The owner must sign an EIP-712 ChangeRecoveryAddress signature approving the change.

ParametertypeDescription
owneraddressAddress of the fid owner
recoveryaddressThe new recovery address
deadlineuint256Signature deadline
sigbytesEIP-712 ChangeRecoveryAddress signature from the to address

ChangeRecoveryAddress signature

To change a recovery address on behalf of an fid owner, the caller must provide an EIP-712 typed signature from the owner address in the following format:

ChangeRecoveryAddress(uint256 fid,address from,address to,uint256 nonce,uint256 deadline)

ParametertypeDescription
fiduint256The owner's fid
fromaddressThe previous recovery address
toaddressThe new recovery address
nonceuint256Current nonce of the signer address
deadlineuint256Signature expiraiton 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.signChangeRecoveryAddress({
  fid: 1n,
  from: '0x00000000FcB080a4D6c39a9354dA9EB9bC104cd7',
  to: '0xD7029BDEa1c17493893AAfE29AAD69EF892B8ff2',
  nonce,
  deadline,
});
ts
import { ID_REGISTRY_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_REGISTRY_EIP_712_TYPES,
  primaryType: 'ChangeRecoveryAddress',
  message: {
    fid: 1n,
    from: '0x00000000FcB080a4D6c39a9354dA9EB9bC104cd7',
    to: '0xD7029BDEa1c17493893AAfE29AAD69EF892B8ff2',
    nonce,
    deadline,
  },
});
ts
import { ID_REGISTRY_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_REGISTRY_ADDRESS,
    abi: idRegistryABI,
    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...');

transferFor

Transfer the fid owned by the from address to the to address. The caller must provide two EIP-712 Transfer signatures: one from the from address authorizing the transfer out and one from the to address accepting the transfer in. These messages have the same format. The to address must not already own an fid.

ParametertypeDescription
fromaddressThe address to transfer the fid from
toaddressThe address to transfer the fid to
fromDeadlineuint256Signature deadline
fromSigbytesEIP-712 Transfer signature from the from address
toDeadlineuint256Signature deadline
toSigbytesEIP-712 Transfer signature from the to address

transferAndChangeRecoveryFor

Transfer the fid owned by the from address to the to address, and change the fid's recovery address. This can be used to safely receive an fid transfer from an untrusted address.

The caller must provide two EIP-712 TransferAndChangeRecovery signatures: one from the from address authorizing the transfer out and one from the to address accepting the transfer in. These messages have the same format. The to address must not already own an fid.

ParametertypeDescription
fromaddressThe address to transfer the fid from
toaddressThe address to transfer the fid to
recoveryaddressThe new recovery address
fromDeadlineuint256Signature deadline
fromSigbytesEIP-712 TransferAndChangeRecovery signature from the from address
toDeadlineuint256Signature deadline
toSigbytesEIP-712 TransferAndChangeRecovery signature from the to address

recoverFor

Transfer an fid to a new address with a signature from the fid's recovery address. The caller must provide two EIP-712 Transfer signatures: one from the recovery address authorizing the transfer out and one from the to address accepting the transfer in. These messages have the same format.

The to address must not already own an fid.

ParametertypeDescription
fromaddressThe address to transfer the fid from
toaddressThe address to transfer the fid to
recoveryDeadlineuint256The deadline for the recovery signature
recoverySigbytesEIP-712 Transfer signature from the recovery address
toDeadlineuint256The deadline for the receiver signature
toSigbytesEIP-712 Transfer signature from the to address

Errors

ErrorSelectorDescription
HasIdf90230a9The to address already owns an fid.
HasNoId210b4b26The from address does not own an fid.
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

IdRegistry.sol