-
-
Save tommy-ca/532ece5324b84cd7c09e4995b00ff18a to your computer and use it in GitHub Desktop.
Register a Farcaster FID and Signer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createThirdwebClient, simulateTransaction } from "thirdweb"; | |
| import { sendAndConfirmTransaction } from "thirdweb/transaction"; | |
| import { privateKeyToAccount } from "thirdweb/wallets"; | |
| import { | |
| createEd25519Keypair, | |
| registerFidAndSigner, | |
| } from "thirdweb/extensions/farcaster"; | |
| import { optimism } from "thirdweb/chains"; | |
| const ANVIL_PRIVATE_KEY_A = | |
| "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" as const; | |
| const ANVIL_PRIVATE_KEY_B = | |
| "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d" as const; | |
| const RECOVERY_ADDRESS = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8" as const; | |
| const client = createThirdwebClient({ | |
| secretKey: "TEST", | |
| }); | |
| const appAccount = privateKeyToAccount({ | |
| client, | |
| privateKey: ANVIL_PRIVATE_KEY_A, | |
| }); | |
| const userAccount = privateKeyToAccount({ | |
| client, | |
| privateKey: ANVIL_PRIVATE_KEY_B, | |
| }); | |
| const signer = await createEd25519Keypair(); | |
| const _registerFidAndSigner = registerFidAndSigner({ | |
| client, | |
| chain: optimism, | |
| recoveryAddress: RECOVERY_ADDRESS, | |
| appAccount, | |
| userAccount, | |
| signerPublicKey: signer.publicKey, | |
| }); | |
| const userFid = await simulateTransaction({ | |
| transaction: _registerFidAndSigner, | |
| account: appAccount, | |
| }); | |
| const registerFidAndSignerResult = await sendAndConfirmTransaction({ | |
| transaction: _registerFidAndSigner, | |
| account: appAccount, | |
| }); | |
| console.log( | |
| `Successfully registered an FID and signer for account ${userAccount.address} | User FID:`, | |
| userFid | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment