Examples
Common SDK use cases and patterns.
note
The SDK returns transaction data for operations that require blockchain transactions. You must submit these transactions using your own wallet. For read-only operations (prices, balances), you receive responses directly.
If you want Bankr to execute transactions for you, use the Agent API instead.
Price Queries
import { BankrClient } from '@bankr/sdk';
const client = new BankrClient({
privateKey: process.env.PRIVATE_KEY as `0x${string}`,
baseUrl: 'https://api.bankr.bot',
});
// Get token price (read-only, no transaction needed)
const result = await client.promptAndWait({
prompt: 'what is the price of ETH?',
});
console.log(result.response);
// Get multiple prices
const prices = await client.promptAndWait({
prompt: 'prices of ETH, BTC, and SOL',
});
console.log(prices.response);
Token Swaps
// Swap request - returns transaction data
const swap = await client.promptAndWait({
prompt: 'swap $50 of ETH to USDC on base',
});
// You must submit the transaction yourself
if (swap.transactions?.length) {
for (const tx of swap.transactions) {
// Submit using your wallet (e.g., viem)
// const hash = await walletClient.sendTransaction(tx.metadata.transaction);
console.log('Transaction to submit:', tx.metadata.transaction);
}
}
// Other swap examples
const swap2 = await client.promptAndWait({ prompt: 'swap 0.1 ETH to USDC' });
const swap3 = await client.promptAndWait({ prompt: 'swap 50% of my USDC to ETH' });
const swap4 = await client.promptAndWait({ prompt: 'sell all my BNKR for ETH' });
Balance Checks
// All balances
const balances = await client.promptAndWait({
prompt: 'what are my token balances?',
});
// Specific chain
const baseBalances = await client.promptAndWait({
prompt: 'my balances on base',
});
// Specific token
const usdcBalance = await client.promptAndWait({
prompt: 'how much USDC do I have?',
});
Token Launching
// Simple launch
const launch = await client.promptAndWait({
prompt: 'deploy a token called MyAgent with symbol AGENT on base',
timeout: 600000, // 10 minute timeout for launches
});
// Launch with vesting
const vestedLaunch = await client.promptAndWait({
prompt: 'launch a token called TeamCoin on solana',
timeout: 600000,
});
console.log(launch.response);
// Includes contract address, pool URL, etc.
Limit Orders
// Buy on dip
const limitBuy = await client.promptAndWait({
prompt: 'buy 100 BNKR if it drops 10%',
});
// Sell on pump
const limitSell = await client.promptAndWait({
prompt: 'sell my BNKR when it rises 20%',
});
DCA Orders
// Daily DCA
const dca = await client.promptAndWait({
prompt: 'DCA $100 USDC into BNKR every day at 9am',
});
// Hourly DCA with limit
const dcaLimited = await client.promptAndWait({
prompt: 'DCA $50 ETH into BNKR every 6 hours for 7 days',
});
Polymarket Betting
// Search markets
const markets = await client.promptAndWait({
prompt: 'what are the odds the eagles win this weekend?',
});
// Place bet
const bet = await client.promptAndWait({
prompt: 'bet $5 on eagles to win tonight',
});
Leveraged Trading
// Simple long
const long = await client.promptAndWait({
prompt: 'buy $10 of GOLD',
});
// Long with leverage and stops
const leveragedLong = await client.promptAndWait({
prompt: 'buy $50 of BTC/USD with 10x leverage, 5% stop loss, and 200% take profit',
});
// Short position
const short = await client.promptAndWait({
prompt: 'short $25 of ETH/USD with 5x leverage',
});
Transfers
// Send ETH
const sendEth = await client.promptAndWait({
prompt: 'send 0.1 ETH to 0x1234...',
});
// Send tokens
const sendTokens = await client.promptAndWait({
prompt: 'send 100 USDC to @username on twitter',
});
Fee Management
// Check fees
const fees = await client.promptAndWait({
prompt: 'how much fees have I earned from my tokens?',
});
// Claim fees
const claim = await client.promptAndWait({
prompt: 'claim my fees for MyToken',
});
Building an Agent
tip
For most agent use cases, the Agent API is simpler because it handles transaction execution for you. Use the SDK only if you need to manage your own wallet and transaction submission.
Complete example using the SDK:
import { BankrClient } from '@bankr/sdk';
class TradingAgent {
private client: BankrClient;
constructor(privateKey: `0x${string}`) {
this.client = new BankrClient({
privateKey,
baseUrl: 'https://api.bankr.bot',
});
}
async getPrice(token: string): Promise<string> {
const result = await this.client.promptAndWait({
prompt: `what is the price of ${token}?`,
});
return result.response || 'Unable to get price';
}
// Returns transaction data - you must submit it yourself
async prepareSwap(amount: number, from: string, to: string, chain: string) {
const result = await this.client.promptAndWait({
prompt: `swap $${amount} of ${from} to ${to} on ${chain}`,
});
return {
response: result.response,
transactions: result.transactions, // Submit these with your wallet
};
}
async checkBalances(): Promise<string> {
const result = await this.client.promptAndWait({
prompt: 'what are my token balances?',
});
return result.response || 'Unable to get balances';
}
}
// Usage
const agent = new TradingAgent(process.env.PRIVATE_KEY as `0x${string}`);
const price = await agent.getPrice('ETH');
const balances = await agent.checkBalances();
const swapData = await agent.prepareSwap(50, 'USDC', 'ETH', 'base');
// Submit transactions using your wallet infrastructure
if (swapData.transactions?.length) {
// walletClient.sendTransaction(swapData.transactions[0].metadata.transaction);
}