Bankr x402 SDK - Client Patterns
FreeNo executable scriptsNot checkedThis skill should be used when the user asks to "implement Bankr SDK client", "write bankr-client.ts", "create SDK client setup", "common files for SDK…
by BankrBot★ 88 GitHub starsAbout this skill
x402 SDK Client Patterns
Reusable client code and common files for Bankr SDK projects.
bankr-client.ts
The core SDK client module for all Bankr SDK projects:
import "dotenv/config";
import { BankrClient } from "@bankr/sdk";
// ============================================
// Validation
// ============================================
if (!process.env.BANKR_PRIVATE_KEY) {
throw new Error(
"BANKR_PRIVATE_KEY environment variable is required. " +
"This wallet pays $0.01 USDC per request (needs USDC on Base)."
);
}
// ============================================
// Client Setup
// ============================================
/**
* Bankr SDK Client
*
* Provides AI-powered Web3 operations with x402 micropayments.
* Each API request costs $0.01 USDC (paid from payment wallet on Base).
*
* @example
* ```typescript
* import { bankrClient } from "./bankr-client";
*
* // Token swap
* const swap = await bankrClient.promptAndWait({
* prompt: "Swap 0.1 ETH to USDC on Base",
* });
*
* // Check balances
* const balances = await bankrClient.promptAndWait({
* prompt: "What are my token balances?",
* });
* ```
*
* @see https://www.npmjs.com/package/@bankr/sdk
*/
export const bankrClient = new BankrClient({
// Required: Payment wallet private key
// This wallet pays $0.01 USDC per API request (must have USDC on Base)
privateKey: process.env.BANKR_PRIVATE_KEY as `0x${string}`,
// Optional: Override receiving wallet address
// If not set, tokens are sent to the payment wallet address
walletAddress: process.env.BANKR_WALLET_ADDRESS,
// Optional: API endpoint (defaults to production)
...(process.env.BANKR_API_URL && { baseUrl: process.env.BANKR_API_URL }),
});
// Export the wallet address for reference
export const walletAddress = bankrClient.getWalletAddress();
// ============================================
// Types (re-exported from SDK)
// ============================================
export type { JobStatusResponse, Transaction } from "@bankr/sdk";
executor.ts
Transaction execution helper using viem:
import { createWalletClient, http, type WalletClient } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base, mainnet, polygon } from "viem/chains";
import type { Transaction } from "@bankr/sdk";
// Chain configuration
const chains = {
8453: base,
1: mainnet,
137: polygon,
} as const;
// Create wallet client for transaction execution
const account = privateKeyToAccount(
process.env.BANKR_PRIVATE_KEY as `0x${string}`
);
function getWalletClient(chainId: number): WalletClient {
const chain = chains[chainId as keyof typeof chains];
if (!chain) {
throw new Error(`Unsupported chain ID: ${chainId}`);
}
return createWalletClient({
account,
chain,
transport: http(),
});
}
/**
* Execute a transaction returned by the Bankr SDK
*
* @example
* ```typescript
* const result = await bankrClient.promptAndWait({
* prompt: "Swap 0.1 ETH to USDC",
* });
*
* if (result.transactions?.length) {
* const hash = await executeTransaction(result.transactions[0]);
* console.log("Transaction:", hash);
* }
* ```
*/
export async function executeTransaction(tx: Transaction): Promise<string> {
const txData = tx.metadata.transaction;
const client = getWalletClient(txData.chainId);
console.log(`Executing ${tx.type} on chain ${txData.chainId}...`);
const hash = await client.sendTransaction({
to: txData.to as `0x${string}`,
data: txData.data as `0x${string}`,
value: BigInt(txData.value || "0"),
gas: BigInt(txData.gas),
});
console.log(`Transaction submitted: ${hash}`);
return hash;
}
/**
* Execute all transactions from a Bankr result
*/
export async function executeAllTransactions(
transactions: Transaction[]
): Promise<string[]> {
const hashes: string[] = [];
for (const tx of transactions) {
const hash = await executeTransaction(tx);
hashes.push(hash);
}
return hashes;
}
Common Files
package.json
Base package.json for all Bankr SDK projects:
{
"name": "{project-name}",
"version": "0.1.0",
"description": "{description}",
"type": "module",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"start": "node dist/index.js",
"dev": "tsx src/index.ts"
},
"dependencies": {
"@bankr/sdk": "^1.0.0",
"dotenv": "^16.3.1",
"viem": "^2.0.0"
},
"devDependencies": {
"@types/node": "^20.10.0",
"tsx": "^4.7.0",
"typescript": "^5.3.0"
}
}
Framework-Specific Dependencies
Add based on project template:
Web Service (Express):
"dependencies": {
"express": "^4.18.0"
},
"devDependencies": {
"@types/express": "^4.17.21"
}
CLI:
"dependencies": {
"commander": "^12.0.0"
}
tsconfig.json
TypeScript configuration:
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
Install Bankr x402 SDK - Client Patterns in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the Bankr x402 SDK - Client Patterns skill do?
This skill should be used when the user asks to "implement Bankr SDK client", "write bankr-client.ts", "create SDK client setup", "common files for SDK project", "package.json for Bankr SDK", "tsconfig for Bankr", "SDK TypeScript patterns", "execute SDK transactions", or needs the reusable client code and common project files for Bankr SDK integrations.
How do I install the Bankr x402 SDK - Client Patterns skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the Bankr x402 SDK - Client Patterns skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
by Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
by Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
by Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
by Anthropic