internet-court/internet-court-skill / vendored/dflow/dflow-phantom-connect
dflow-phantom-connect
VerifiedBuild Solana wallet-connected apps with Phantom Connect SDKs and DFlow spot trading. Use when user asks to connect a Phantom wallet, integrate Phantom in React, React Native, or vanilla JS, sign messages or transactions, build token-gated pages, mint NFTs, accept crypto payments, or swap/stream tokens with DFlow. Covers @phantom/react-sdk, @phantom/react-native-sdk, @phantom/browser-sdk, and DFlow spot trading and market-data streaming. Do NOT use for Ethereum or EVM wallet integrations, or non-DFlow DEX routing.
| File | Kind | Size |
|---|---|---|
| LICENSE | other | 1.0 KB |
| SKILL.md | skill md | 7.0 KB |
| references/browser-sdk.md | markdown | 8.1 KB |
| references/dflow-crypto-trading.md | markdown | 4.9 KB |
| references/dflow-websockets.md | markdown | 4.3 KB |
| references/nft-minting.md | markdown | 4.6 KB |
| references/payments.md | markdown | 5.5 KB |
| references/react-native-sdk.md | markdown | 7.2 KB |
| references/react-sdk.md | markdown | 7.1 KB |
| references/token-gating.md | markdown | 4.9 KB |
| references/transactions.md | markdown | 5.1 KB |
references/token-gating.md
View on GitHub# Token-Gated Access
Implement token-gated features that require users to hold specific tokens.
## Architecture
```
1. User connects wallet (Phantom Connect)
2. App gets wallet address
3. Query blockchain for token balance
4. If balance meets criteria → grant access
5. Optional: Sign message to prove ownership (recommended for security)
```
## Client-Side Gating (Simple)
Best for low-stakes content and UI personalization.
```tsx
import { useAccounts } from "@phantom/react-sdk";
import { Connection, PublicKey } from "@solana/web3.js";
import { getAccount, getAssociatedTokenAddress } from "@solana/spl-token";
const TOKEN_MINT = "YOUR_TOKEN_MINT_ADDRESS";
const REQUIRED_AMOUNT = 1;
function TokenGatedContent() {
const { addresses, isConnected } = useAccounts();
const [hasAccess, setHasAccess] = useState(false);
const [loading, setLoading] = useState(true);
useEffect(() => {
if (!isConnected) { setLoading(false); return; }
checkBalance();
}, [isConnected, addresses]);
async function checkBalance() {
const wallet = addresses.find(a => a.addressType === "solana")?.address;
if (!wallet) return;
const connection = new Connection("https://api.mainnet-beta.solana.com");
try {
const ata = await getAssociatedTokenAddress(
new PublicKey(TOKEN_MINT),
new PublicKey(wallet)
);
const account = await getAccount(connection, ata);
setHasAccess(Number(account.amount) >= REQUIRED_AMOUNT);
} catch {
setHasAccess(false);
} finally {
setLoading(false);
}
}
if (!isConnected) return <ConnectPrompt />;
if (loading) return <Loading />;
if (!hasAccess) return <AccessDenied />;
return <ProtectedContent />;
}
```
## Server-Side Verification (Secure)
Best for valuable content and actual access control.
### Client: Sign Message
```tsx
import { useSolana, useAccounts } from "@phantom/react-sdk";
async function verifyAccess() {
const { solana } = useSolana();
const address = await solana.getPublicKey();
const timestamp = Date.now();
const message = `Verify ownership\nAddress: ${address}\nTimestamp: ${timestamp}`;
const { signature } = await solana.signMessage(message);
const res = await fetch("/api/verify-access", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ address, signature, message, timestamp }),
});
return await res.json();
}
```
### Server: Verify Signature + Check Balance
```ts
import { Connection, PublicKey } from "@solana/web3.js";
import { getAccount, getAssociatedTokenAddress } from "@solana/spl-token";
import nacl from "tweetnacl";
import bs58 from "bs58";
import jwt from "jsonwebtoken";
export async function POST(req: Request) {
const { address, signature, message, timestamp } = await req.json();
// 1. Check timestamp (5 min window)
if (Date.now() - timestamp > 5 * 60 * 1000) {
return Response.json({ error: "Expired" }, { status: 400 });
}
// 2. Verify signature
const isValid = nacl.sign.detached.verify(
new TextEncoder().encode(message),
bs58.decode(signature),
bs58.decode(address)
);
if (!isValid) {
return Response.json({ error: "Invalid signature" }, { status: 401 });
}
// 3. Check token balance
const connection = new Connection("https://api.mainnet-beta.solana.com");
try {
const ata = await getAssociatedTokenAddress(
new PublicKey(TOKEN_MINT),
new PublicKey(address)
);
const account = await getAccount(connection, ata);
const balance = Number(account.amount);
if (balance < REQUIRED_BALANCE) {
return Response.json({ hasAccess: false, balance });
}
const accessToken = jwt.sign({ address, balance }, JWT_SECRET, { expiresIn: "24h" });
return Response.json({ hasAccess: true, accessToken });
} catch {
return Response.json({ hasAccess: false, balance: 0 });
}
}
```
## NFT Collection Gating
```ts
import { Metaplex } from "@metaplex-foundation/js";
async function checkNFTOwnership(wallet: string, collection: string) {
const connection = new Connection("https://api.mainnet-beta.solana.com");
const metaplex = Metaplex.make(connection);
const nfts = await metaplex.nfts().findAllByOwner({
owner: new PublicKey(wallet),
});
return nfts.some(nft => nft.collection?.address.toString() === collection);
}
```
## SOL Balance Gating
```ts
async function checkSolBalance(wallet: string, requiredSol: number) {
const connection = new Connection("https://api.mainnet-beta.solana.com");
const balance = await connection.getBalance(new PublicKey(wallet));
const solBalance = balance / 1e9; // Convert lamports to SOL
return solBalance >= requiredSol;
}
```
## Security Best Practices
1. **Always verify server-side** for valuable content
2. **Use message signing** to prove wallet ownership
3. **Include timestamps** to prevent replay attacks
4. **Cache verification** with short TTLs
5. **Re-verify on sensitive actions**
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |