Client Setup
Configure the BankrClient for your application.
Basic Setup
import { BankrClient } from '@bankr/sdk';
const client = new BankrClient({
privateKey: '0xYourPrivateKey',
});
Configuration Options
privateKey (required)
Your wallet's private key, used for:
- Signing x402 payment transactions
- Authenticating job status requests
const client = new BankrClient({
privateKey: '0x1234567890abcdef...',
});
The wallet address is automatically derived from the private key.
baseUrl (optional)
API endpoint. We recommend explicitly setting the production URL.
const client = new BankrClient({
privateKey: '0x...',
baseUrl: 'https://api.bankr.bot', // Production (recommended)
});
timeout (optional)
Request timeout in milliseconds. Default: 10 minutes.
const client = new BankrClient({
privateKey: '0x...',
timeout: 300000, // 5 minutes
});
walletAddress (optional)
Override the context wallet for operations. By default, uses the address derived from your private key.
const client = new BankrClient({
privateKey: '0x...', // Payment wallet
walletAddress: '0xDifferentWallet', // Context wallet
});
This is useful when:
- Your payment wallet differs from your trading wallet
- You're building a service that operates on behalf of users
Getting the Wallet Address
Retrieve the derived wallet address:
const client = new BankrClient({
privateKey: '0x...',
});
const address = client.getWalletAddress();
console.log(address); // "0xYourDerivedAddress"
Multiple Clients
You can create multiple clients for different wallets:
const personalClient = new BankrClient({
privateKey: process.env.PERSONAL_KEY as `0x${string}`,
});
const agentClient = new BankrClient({
privateKey: process.env.AGENT_KEY as `0x${string}`,
});
Error Handling
The client throws errors for invalid configuration:
try {
const client = new BankrClient({
privateKey: 'invalid', // Must be 0x-prefixed hex
});
} catch (error) {
console.error('Invalid private key format');
}
Security Best Practices
- Never hardcode private keys — Use environment variables
- Use separate wallets — Don't use your main wallet for API operations
- Limit wallet funds — Only keep necessary USDC for payments
- Rotate keys periodically — Create new wallets when needed
// Good
const client = new BankrClient({
privateKey: process.env.BANKR_PRIVATE_KEY as `0x${string}`,
});
// Bad - never do this
const client = new BankrClient({
privateKey: '0xActualPrivateKeyHardcoded',
});