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 an fid follows an FID
Get the follow graph for a given address and FID.
getGraph(uint256 _from, uint256 _to, uint256 _graphType) external view returns (TimestampedValue memory);YourContract.sol
1import "./IFaracle.sol";
2import "./FaracleHelper.sol";
3
4contract MintIfFollower {
5
6 IFaracle public faracle = IFaracle(0x687d65ce04abbca3dac57cda6c358e497bfd320e);
7
8 uint256 YourProductFid = 123456; // Replace with the FID you want to check for followers
9
10 constructor() {}
11
12 function mintIfFollower() public {
13
14 uint256 fid = faracle.getFidByVerifiedAddress(msg.sender);
15
16 require(fid != 0, "Address not linked to any FID!");
17
18 TimestampedValue memory followData = faracle.getGraph(fid, YourProductFid, SocialGraphType.Follow);
19 require(followData.value == 1, "You must follow the product FID to mint!");
20
21 // Proceed with minting logic
22 }
23
24}Check if an fid follows multiple FIDs
Get the follow graph for a given address and multiple FIDs.
getGraph(uint256 _from, uint256[] _toList, uint256 _graphType) external view returns (TimestampedValue[] memory);YourContract.sol
1import "./IFaracle.sol";
2import "./FaracleHelper.sol";
3
4contract MintIfUserFollowsOurTeam {
5
6 IFaracle public faracle = IFaracle(0x687d65ce04abbca3dac57cda6c358e497bfd320e);
7
8 // FId of all the founders of your product
9 uint256[] memory foundersFid = new uint256[](3);
10 foundersFid[0] = 123456; // Replace with actual FIDs
11 foundersFid[1] = 234567;
12 foundersFid[2] = 345678;
13
14 constructor() {}
15
16 function mintIfUserFollowsOurTeam() public {
17
18 uint256 fid = faracle.getFidByVerifiedAddress(msg.sender);
19
20 require(fid != 0, "Address not linked to any FID!");
21
22 TimestampedValue[] memory followData = faracle.getGraph(fid, foundersFid, SocialGraphType.Follow);
23
24 // Check if user follows all of the founders
25 for (uint256 i = 0; i < followData.length; i++) {
26 require(followData[i].value == 1, "You must follow all founders to mint!");
27 }
28
29 // Proceed with minting logic
30 }
31
32}Check if multiple FIDs follow an fid
Get the follow graph for multiple FIDs and a given FID.
getGraph(uint256[] _fromList, uint256 _to, uint256 _graphType) external view returns (TimestampedValue[] memory);YourContract.sol
1import "./IFaracle.sol";
2import "./FaracleHelper.sol";
3
4contract MintIfAnyOneFoundersFollowsYou {
5
6 IFaracle public faracle = IFaracle(0x687d65ce04abbca3dac57cda6c358e497bfd320e);
7
8 // FId of all the founders of your product
9 uint256[] memory foundersFid = new uint256[](3);
10 foundersFid[0] = 123456; // Replace with actual FIDs
11 foundersFid[1] = 234567;
12 foundersFid[2] = 345678;
13
14 constructor() {}
15
16 function mintIfAnyOneFoundersFollowsYou() public {
17
18 uint256 fid = faracle.getFidByVerifiedAddress(msg.sender);
19
20 require(fid != 0, "Address not linked to any FID!");
21
22 TimestampedValue[] memory followData = faracle.getGraph(foundersFid, fid, SocialGraphType.Follow);
23
24 uint256 followedCount = 0;
25
26 // Check if any one of the founders follows the user
27 for (uint256 i = 0; i < followData.length; i++) {
28 if(followData[i].value == 1) {
29 followedCount++;
30 break
31 }
32 }
33
34 require(followedCount > 0, "At least one founder must follow you to mint!");
35
36 // Proceed with minting logic
37 }
38
39}Check the graph between multiple FIDs
Get the follow graph for multiple to and from FIDs.
getGraph(uint256[] _fromList, uint256[] _toList, uint256 _graphType) external view returns (TimestampedValue[] memory);YourContract.sol
1import "./IFaracle.sol";
2import "./FaracleHelper.sol";
3
4contract MintIfMutualFollow {
5
6 IFaracle public faracle = IFaracle(0x687d65ce04abbca3dac57cda6c358e497bfd320e);
7
8 uint256 foundersFid = 12312; // Replace with actual FID
9
10 constructor() {}
11
12 function mintIfMutualFollow() public {
13
14 uint256 fid = faracle.getFidByVerifiedAddress(msg.sender);
15
16 require(fid != 0, "Address not linked to any FID!");
17
18 TimestampedValue[] memory followData = faracle.getGraph([foundersFid, fid], [fid, foundersFid], SocialGraphType.Follow);
19
20 require(followData[0].value == 1 && followData[1].value == 1, "Mutual follow required to mint!");
21
22 // Proceed with minting logic
23 }
24
25}Check if an address follows an FID
Get the graph between the given address and FID.
getGraphByAddress(address _fromAddress, uint256 _to, uint256 _graphType) external view returns (TimestampedValue memory);YourContract.sol
1import "./IFaracle.sol";
2import "./FaracleHelper.sol";
3
4contract MintIfFollower {
5
6 IFaracle public faracle = IFaracle(0x687d65ce04abbca3dac57cda6c358e497bfd320e);
7
8 uint256 YourProductFid = 123456; // Replace with the FID you want to check for followers
9
10 constructor() {}
11
12 function mintIfFollower() public {
13
14 TimestampedValue memory followData = faracle.getGraphByAddress(msg.sender, YourProductFid, SocialGraphType.Follow);
15 require(followData.value == 1, "You must follow the product FID to mint!");
16
17 // Proceed with minting logic
18 }
19
20}Check if an address follows multiple FIDs
Get the graph between the given address and multiple FIDs.
getGraphByAddress(address _fromAddress, uint256[] _toList, uint256 _graphType) external view returns (TimestampedValue[] memory);YourContract.sol
1import "./IFaracle.sol";
2import "./FaracleHelper.sol";
3
4contract MintIfUserFollowsOurTeam {
5
6 IFaracle public faracle = IFaracle(0x687d65ce04abbca3dac57cda6c358e497bfd320e);
7
8 // FId of all the founders of your product
9 uint256[] memory foundersFid = new uint256[](3);
10 foundersFid[0] = 123456; // Replace with actual FIDs
11 foundersFid[1] = 234567;
12 foundersFid[2] = 345678;
13
14 constructor() {}
15
16 function mintIfUserFollowsOurTeam() public {
17
18 TimestampedValue[] memory followData = faracle.getGraphByAddress(msg.sender, foundersFid, SocialGraphType.Follow);
19
20 // Check if user follows all of the founders
21 for (uint256 i = 0; i < followData.length; i++) {
22 require(followData[i].value == 1, "You must follow all founders to mint!");
23 }
24
25 // Proceed with minting logic
26 }
27
28}Check if multiple FIDs follow an address
Get the graph between multiple FIDs and the given address.
getGraphByAddress(uint256[] _fromList, address _to, uint256 _graphType) external view returns (TimestampedValue[] memory);YourContract.sol
1import "./IFaracle.sol";
2import "./FaracleHelper.sol";
3
4contract MintIfAnyOneFoundersFollowsYou {
5
6 IFaracle public faracle = IFaracle(0x687d65ce04abbca3dac57cda6c358e497bfd320e);
7
8 // FId of all the founders of your product
9 uint256[] memory foundersFid = new uint256[](3);
10 foundersFid[0] = 123456; // Replace with actual FIDs
11 foundersFid[1] = 234567;
12 foundersFid[2] = 345678;
13
14 constructor() {}
15
16 function mintIfAnyOneFoundersFollowsYou() public {
17
18 TimestampedValue[] memory followData = faracle.getGraph(foundersFid, msg.sender, SocialGraphType.Follow);
19
20 uint256 followedCount = 0;
21
22 // Check if any one of the founders follows the user
23 for (uint256 i = 0; i < followData.length; i++) {
24 if(followData[i].value == 1) {
25 followedCount++;
26 break
27 }
28 }
29
30 require(followedCount > 0, "At least one founder must follow you to mint!");
31
32 // Proceed with minting logic
33 }
34
35}Other Social Graph Functions
Other functions related to social graphs.
YourContract.sol
1function getGraphByAddress(address _from, address _to, uint256[] calldata _graphTypes) external view returns (TimestampedValue[] memory) {
2
3}
4
5function getGraph(uint256[] calldata _froms, uint256[] calldata _tos, uint256[] calldata _graphTypes) external view returns (TimestampedValue[] memory) {
6
7}
8
9function getGraph(uint256 _from, uint256 _to, uint256[] calldata _graphTypes) external view returns (TimestampedValue[] memory) {
10
11}