// One command after Kognai makes its three paid test calls (acceptance A5):
// node scripts/kognai-calls.mjs <tx>:<skill_id> <tx>:<skill_id> <tx>:<skill_id>
// e.g. node scripts/kognai-calls.mjs 0xabc..:webread.read 0xdef..:payguard.screen_address 0x123..:domaincheck.domain
// Reads each settlement transaction from Base (public RPC, read only, no key, no spend), checks it is a USDC transfer
// to our payee for that capability's listed price, and saves test/fixtures/kognai-calls.json. The A5 test then checks
// the record offline. Optional: add "answer": <file.json> per call later if Kognai shares the requests and answers.
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
const RPC = process.env.BASE_RPC_URL || 'https://mainnet.base.org';
const USDC = '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913';
const TRANSFER = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
const root = new URL('../', import.meta.url);
const offer = JSON.parse(readFileSync(new URL('lax-offer.json', root)));
const payTo = offer.agent_did.split(':').pop().toLowerCase();
const price = Object.fromEntries(offer.capabilities.filter((c) => c.pricing.model === 'per_call').map((c) => [c.skill_id, c.pricing.amount]));
const atomic = (d) => { const [i, f = ''] = d.split('.'); return BigInt(i + (f + '000000').slice(0, 6)); };
const args = process.argv.slice(2);
if (args.length !== 3 || !args.every((a) => /^0x[0-9a-fA-F]{64}:[\w.]+$/.test(a))) {
console.error('usage: node scripts/kognai-calls.mjs <tx>:<skill_id> x3'); process.exit(2);
}
let id = 0;
const rpc = async (method, params) => {
const r = await (await fetch(RPC, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: ++id, method, params }) })).json();
if (r.error) throw new Error(`${method}: ${r.error.message}`);
return r.result;
};
const calls = [];
for (const a of args) {
const [tx, skill] = a.split(':');
if (!(skill in price)) { console.error(`${skill}: not a per call capability in lax-offer.json`); process.exit(2); }
const rc = await rpc('eth_getTransactionReceipt', [tx]);
if (!rc) { console.error(`${tx}: no receipt on Base`); process.exit(1); }
const log = rc.logs.find((l) => l.address.toLowerCase() === USDC && l.topics[0] === TRANSFER && ('0x' + l.topics[2].slice(26)).toLowerCase() === payTo);
const blk = await rpc('eth_getBlockByNumber', [rc.blockNumber, false]);
calls.push({
skill_id: skill, tx: tx.toLowerCase(), status: rc.status, block: parseInt(rc.blockNumber, 16),
time_utc: new Date(parseInt(blk.timestamp, 16) * 1000).toISOString(),
payer: log ? ('0x' + log.topics[1].slice(26)).toLowerCase() : null, to: log ? payTo : null,
amount_atomic: log ? BigInt(log.data).toString() : null, listed_atomic: atomic(price[skill]).toString(),
});
}
mkdirSync(new URL('test/fixtures/', root), { recursive: true });
writeFileSync(new URL('test/fixtures/kognai-calls.json', root), JSON.stringify({ payTo, recordedAt: new Date().toISOString(), calls }, null, 1) + '\n');
for (const c of calls) console.log(`${c.skill_id}: ${c.tx.slice(0, 12)} status ${c.status} paid ${c.amount_atomic ?? 'NO TRANSFER TO US'} listed ${c.listed_atomic}`);
const ok = calls.every((c) => c.status === '0x1' && c.amount_atomic === c.listed_atomic) && new Set(calls.map((c) => c.skill_id)).size === 3 && new Set(calls.map((c) => c.tx)).size === 3;
console.log(ok ? 'A5 record ok: now run npm test and commit' : 'A5 record has problems (see above)');
process.exit(ok ? 0 : 1);
agentgate-source: code mirror on Cloudflare Pages. All repos