Skip to content

Instantly share code, notes, and snippets.

@stevedylandev
Created March 27, 2024 04:20
Show Gist options
  • Save stevedylandev/86b3145f25d2a873be8e380474cb6176 to your computer and use it in GitHub Desktop.
Save stevedylandev/86b3145f25d2a873be8e380474cb6176 to your computer and use it in GitHub Desktop.
Comparison Between Link Follow and Link Unfollow
import {
Message,
NobleEd25519Signer,
FarcasterNetwork,
LinkBody,
makeLinkAdd
} from "@farcaster/core";
import { hexToBytes } from "@noble/hashes/utils";
const FID = process.env.FID ? parseInt(process.env.FID) : 0;
const SIGNER = process.env.PRIVATE_KEY || "";
async function followFid() {
try {
const dataOptions = {
fid: FID,
network: FarcasterNetwork.MAINNET,
};
const privateKeyBytes = hexToBytes(SIGNER.slice(2));
const ed25519Signer = new NobleEd25519Signer(privateKeyBytes);
const removeBody: LinkBody = {
type: "follow",
targetFid: 20918
}
const followFidReq = await makeLinkAdd(removeBody, dataOptions, ed25519Signer)
const followFid: any = followFidReq._unsafeUnwrap()
const messageBytes = Buffer.from(Message.encode(followFid).finish())
const followRequest = await fetch(
"https://hub.pinata.cloud/v1/submitMessage",
{
method: "POST",
headers: { "Content-Type": "application/octet-stream" },
body: messageBytes,
},
);
const castResult = await followRequest.json();
console.log(castResult);
return castResult
} catch (error) {
console.log("problem sending cast:", error);
}
}
followFid()
//{
// data: {
// type: "MESSAGE_TYPE_LINK_ADD",
// fid: 6023,
// timestamp: 102053717,
// network: "FARCASTER_NETWORK_MAINNET",
// linkBody: {
// type: "follow",
// targetFid: 20918
// }
// },
// hash: "0xe64e1de48da6f18e3ef64a1b6bf3687522e0094e",
// hashScheme: "HASH_SCHEME_BLAKE3",
// signature: "7stATvuoFMxEyzqKpMTmGx5AuJs6jkdwLAi4KSZHSzzQoRbK4CA/yxaKPV7LwZfkjI6GfpQr1g905F8SaF86BA==",
// signatureScheme: "SIGNATURE_SCHEME_ED25519",
// signer: "0xbe16cbbf6c22f6291e551337ae320ae752ce091c3d68ab225ddade773628222b"
//}
import {
Message,
NobleEd25519Signer,
FarcasterNetwork,
LinkBody,
makeLinkRemove
} from "@farcaster/core";
import { hexToBytes } from "@noble/hashes/utils";
const FID = process.env.FID ? parseInt(process.env.FID) : 0;
const SIGNER = process.env.PRIVATE_KEY || "";
async function unfollowFid() {
try {
const dataOptions = {
fid: FID,
network: FarcasterNetwork.MAINNET,
};
const privateKeyBytes = hexToBytes(SIGNER.slice(2));
const ed25519Signer = new NobleEd25519Signer(privateKeyBytes);
const removeBody: LinkBody = {
type: "unfollow",
targetFid: 20918
}
const unfollowFidReq = await makeLinkRemove(removeBody, dataOptions, ed25519Signer)
const unfollowFid: any = unfollowFidReq._unsafeUnwrap()
const messageBytes = Buffer.from(Message.encode(unfollowFid).finish())
const unfollowRequest = await fetch(
"https://hub.pinata.cloud/v1/submitMessage",
{
method: "POST",
headers: { "Content-Type": "application/octet-stream" },
body: messageBytes,
},
);
const castResult = await unfollowRequest.json();
console.log(castResult);
return castResult
} catch (error) {
console.log("problem sending cast:", error);
}
}
unfollowFid()
//{
// data: {
// type: "MESSAGE_TYPE_LINK_REMOVE",
// fid: 6023,
// timestamp: 102053840,
// network: "FARCASTER_NETWORK_MAINNET",
// linkBody: {
// type: "unfollow",
// targetFid: 20918
// }
// },
// hash: "0xcc2f50caa148e32c373906c639c81ce544266efa",
// hashScheme: "HASH_SCHEME_BLAKE3",
// signature: "fIeyk7Xc/DCvLho6WPSIGfTr8lnSj3CoeyDGj343CfAr49K0r3DfWZICI6iaobcqa2Y8RbkI9ic880yIgkxsDg==",
// signatureScheme: "SIGNATURE_SCHEME_ED25519",
// signer: "0xbe16cbbf6c22f6291e551337ae320ae752ce091c3d68ab225ddade773628222b"
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment