import { createBuyer } from '@leash/buyer-kit';
import { createKeyPairSignerFromBytes } from '@solana/kit';
import fs from 'node:fs';
const signer = await createKeyPairSignerFromBytes(
new Uint8Array(JSON.parse(fs.readFileSync(process.env.LEASH_BUYER_SECRET_KEY!, 'utf8'))),
);
const buyer = createBuyer({
agent: process.env.AGENT_ASSET!,
rules: {
v: '0.1',
budget: { daily: '1.0', perCall: '0.01', currency: 'USDC' },
hosts: { allow: ['seller-demo.local'] },
triggers: [],
},
signer,
networks: ['solana-devnet'],
rpcUrl: 'https://api.devnet.solana.com',
// Recommended: spend from the agent treasury, not the executive's wallet.
// Pass the treasury **ATA for the mint you intend to pay with** (same mint
// as `preferredCurrency`). When omitted, buyer-kit can still derive the ATA
// from `agent` + quoted `asset` on failures, but passing it explicitly avoids
// ambiguity. See [Fund an agent](./fund-an-agent).
sourceTokenAccount: process.env.LEASH_BUYER_SOURCE_TOKEN_ACCOUNT,
// When the seller lists multiple stables in `accepts[]`, pick one.
preferredCurrency: 'USDC',
onReceipt: (r) =>
fetch(`http://localhost:8787/a/${r.agent}/receipts`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(r),
}),
});
const { response, receipt } = await buyer.fetch('https://seller-demo.local/tag', {
method: 'POST',
});
console.log(receipt.tx_sig); // real Solana signature