Fid and Address Mapping

Get Fid from an Ethereum address and vice versa directly in your smart contract.

FID from Address

Get the FID from the farcaster verfifed address list.

Example shows how to whitelist only farcaster users.

YourContract.sol
1// Import the Faracle interface
2import "./IFaracle.sol";
3
4contract Whitelist {
5  
6  IFaracle public faracle;
7
8  mapping(uint256 => bool) public whitelisted;
9
10  constructor(address _faracleAddress) {
11    // Initialize the Faracle interface
12    faracle = IFaracle(_faracleAddress);
13  }
14
15  function whitelistMe() public {
16
17    // Get the FID associated with the sender's address
18    uint256 fid = faracle.addressToFid(msg.sender);
19
20    // Ensure the address is linked to a FID
21    require(fid != 0, "Address not linked to any FID!");
22
23    // Check if the FID is already whitelisted
24    require(!whitelisted[fid], "FID already whitelisted!");
25    
26    // Whitelist the FID
27    whitelisted[fid] = true;
28  }
29
30}

Address(es) from FID

Get the verified addresses associated with a Farcaster FID.

Example shows how to get all verified addresses for a given FID.

YourContract.sol
1// Import the Faracle interface
2import "./IFaracle.sol";
3
4contract GetAddresses {
5  
6  IFaracle public faracle;
7
8  constructor(address _faracleAddress) {
9    // Initialize the Faracle interface
10    faracle = IFaracle(_faracleAddress);
11  }
12
13  function getAddresses(uint256 fid) public view returns (address[] memory) {
14
15    // Get the list of verified addresses associated with the FID
16    address[] memory addresses = faracle.fidToAddresses(fid);
17
18    return addresses;
19  }
20
21}

All Verfied Addresses from Address

Get all verified addresses associated with a Farcaster FID from an address.

Example shows total Token balance of all verified addresses for a given FID.

Note: The first item in the address list is considered the primary address.

YourContract.sol
1@todo

Primary Address from FID

Get the primary verified address associated with a Farcaster FID.

Example shows how to get the primary verified address for a given FID.

YourContract.sol
1@todo