Social Graphs and Connections
Check if an address or fid follows another farcaster user.
Imagine you building a social and collateral free lending dapp where users can lend to friends of popular farcaster profiles. This is the right place to start!
Check if user follows another user by Address
Get various social scores for a given Farcaster address.
Example shows swap fees based on neynar score for a given address.
YourContract.sol
1// Import the Faracle interface
2import "./IFaracle.sol";
3
4contract ProfileTimestamps {
5
6 IFaracle public faracle;
7
8 struct TimestampedValue {
9 uint32 timestampChain; //4 Bytes: When this data was last updated in blockchain.
10 uint32 timestampSource; //4 Bytes: When this data was generated in source (e.g. off-chain like snapchain).
11 uint192 value; //24 Bytes: Real Value
12 }
13
14 constructor(address _faracleAddress) {
15 // Initialize the Faracle interface
16 faracle = IFaracle(_faracleAddress);
17 }
18
19 function getFeesBPS(address _user) public view returns (uint256) {
20 // Get the social score by address
21 TimestampedValue memory socialScoreData = faracle.socialScore(_user, 1); // 1 is for Neynar Score
22
23 // Extract the social score value and convert to uint256
24 uint256 socialScore = uint256(socialScoreData.value);
25
26 // Calculate swap fees in basis points (BPS) based on social score
27 // Assuming social score ranges from 0 to 10,000 for 0.00 to 1.00
28 uint256 maxScore = 10000;
29 uint256 maxFeeBPS = 1000; // Maximum fee of 10%
30
31 // Higher the social score, lower the fees
32 uint256 feesBPS = maxFeeBPS * (maxScore - socialScore) / maxScore;
33
34 return feesBPS;
35
36 }
37
38}Check if user follows another user by FID
Get various social scores for a given Farcaster FID.
Example shows swap fees based on neynar score for a given FID.
YourContract.sol
1// Import the Faracle interface
2import "./IFaracle.sol";
3
4contract ProfileTimestamps {
5
6 IFaracle public faracle;
7
8 struct TimestampedValue {
9 uint32 timestampChain; //4 Bytes: When this data was last updated in blockchain.
10 uint32 timestampSource; //4 Bytes: When this data was generated in source (e.g. off-chain like snapchain).
11 uint192 value; //24 Bytes: Real Value
12 }
13
14 constructor(address _faracleAddress) {
15 // Initialize the Faracle interface
16 faracle = IFaracle(_faracleAddress);
17 }
18
19 function getFeesBPS(uint256 _fid) public view returns (uint256) {
20 // Get the social score by address
21 TimestampedValue memory socialScoreData = faracle.socialScore(_fid, 1); // 1 is for Neynar Score
22
23 // Extract the social score value and convert to uint256
24 uint256 socialScore = uint256(socialScoreData.value);
25
26 // Calculate swap fees in basis points (BPS) based on social score
27 // Assuming social score ranges from 0 to 10,000 for 0.00 to 1.00
28 uint256 maxScore = 10000;
29 uint256 maxFeeBPS = 1000; // Maximum fee of 10%
30
31 // Higher the social score, lower the fees
32 uint256 feesBPS = maxFeeBPS * (maxScore - socialScore) / maxScore;
33
34 return feesBPS;
35
36 }
37
38}