x402-bazaar 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +1 -1
- package/package.json +1 -1
- package/src/commands/init.js +88 -41
package/bin/cli.js
CHANGED
package/package.json
CHANGED
package/src/commands/init.js
CHANGED
|
@@ -191,8 +191,8 @@ export async function initCommand(options) {
|
|
|
191
191
|
|
|
192
192
|
console.log('');
|
|
193
193
|
|
|
194
|
-
// ─── Step 3: Wallet Configuration
|
|
195
|
-
log.step(3, 'Configuring wallet...');
|
|
194
|
+
// ─── Step 3: Network & Wallet Configuration ────────────────────────
|
|
195
|
+
log.step(3, 'Configuring network and wallet...');
|
|
196
196
|
console.log('');
|
|
197
197
|
|
|
198
198
|
let walletMode = 'readonly';
|
|
@@ -207,6 +207,42 @@ export async function initCommand(options) {
|
|
|
207
207
|
log.info('Skipping wallet setup (--no-wallet)');
|
|
208
208
|
walletMode = 'readonly';
|
|
209
209
|
} else {
|
|
210
|
+
// Network & Budget first — needed for wallet funding instructions
|
|
211
|
+
const configOverrides = {};
|
|
212
|
+
if (options.network) configOverrides.network = options.network;
|
|
213
|
+
if (options.budget) configOverrides.maxBudget = options.budget;
|
|
214
|
+
|
|
215
|
+
const configAnswers = await promptOrDefault([
|
|
216
|
+
{
|
|
217
|
+
type: 'list',
|
|
218
|
+
name: 'network',
|
|
219
|
+
message: 'Which network?',
|
|
220
|
+
choices: [
|
|
221
|
+
{ name: 'Base Mainnet (real USDC)', value: 'mainnet' },
|
|
222
|
+
{ name: 'Base Sepolia (testnet, free tokens for testing)', value: 'testnet' },
|
|
223
|
+
{ name: 'SKALE Europa (zero gas fees — advanced users)', value: 'skale' },
|
|
224
|
+
],
|
|
225
|
+
default: 'mainnet',
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
type: 'input',
|
|
229
|
+
name: 'maxBudget',
|
|
230
|
+
message: 'Max USDC budget per session (safety limit):',
|
|
231
|
+
default: '1.00',
|
|
232
|
+
validate: (v) => {
|
|
233
|
+
const n = parseFloat(v);
|
|
234
|
+
if (isNaN(n) || n <= 0) return 'Must be a positive number';
|
|
235
|
+
if (n > 100) return 'Maximum is 100 USDC per session';
|
|
236
|
+
return true;
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
], configOverrides);
|
|
240
|
+
|
|
241
|
+
network = configAnswers.network;
|
|
242
|
+
maxBudget = configAnswers.maxBudget;
|
|
243
|
+
|
|
244
|
+
console.log('');
|
|
245
|
+
|
|
210
246
|
const { mode } = await promptOrDefault([{
|
|
211
247
|
type: 'list',
|
|
212
248
|
name: 'mode',
|
|
@@ -239,15 +275,45 @@ export async function initCommand(options) {
|
|
|
239
275
|
log.success('New wallet generated!');
|
|
240
276
|
|
|
241
277
|
// Derive address using viem (installed in step 2)
|
|
278
|
+
let walletAddress = '';
|
|
242
279
|
try {
|
|
243
|
-
|
|
280
|
+
walletAddress = execSync(
|
|
244
281
|
`node --input-type=module -e "import{privateKeyToAccount}from'viem/accounts';console.log(privateKeyToAccount('${agentPrivateKey}').address)"`,
|
|
245
282
|
{ cwd: installDir, stdio: 'pipe', timeout: 15000 }
|
|
246
283
|
).toString().trim();
|
|
247
|
-
log.info(`Wallet address: ${chalk.bold(addr)}`);
|
|
248
284
|
console.log('');
|
|
249
|
-
log.
|
|
250
|
-
|
|
285
|
+
log.info(`Wallet address: ${chalk.bold(walletAddress)}`);
|
|
286
|
+
if (network === 'skale') {
|
|
287
|
+
log.dim(` Explorer: https://elated-tan-skat.explorer.mainnet.skalenodes.com/address/${walletAddress}`);
|
|
288
|
+
} else {
|
|
289
|
+
log.dim(` BaseScan: https://basescan.org/address/${walletAddress}`);
|
|
290
|
+
}
|
|
291
|
+
console.log('');
|
|
292
|
+
log.separator();
|
|
293
|
+
if (network === 'skale') {
|
|
294
|
+
log.info(chalk.bold('To activate payments, fund this wallet:'));
|
|
295
|
+
console.log('');
|
|
296
|
+
log.dim(` ${chalk.white('1.')} Bridge USDC to SKALE Europa`);
|
|
297
|
+
log.dim(` (Use https://portal.skale.space/bridge or any SKALE bridge)`);
|
|
298
|
+
log.dim(` ${chalk.white('2.')} Send ${chalk.bold('USDC')} to: ${chalk.hex('#34D399')(walletAddress)}`);
|
|
299
|
+
log.dim(` (Even $1 USDC is enough — each API call costs $0.005-$0.05)`);
|
|
300
|
+
log.dim(` ${chalk.white('3.')} Get free sFUEL for gas at https://www.sfuelstation.com/`);
|
|
301
|
+
log.dim(` (sFUEL is free — no ETH needed on SKALE!)`);
|
|
302
|
+
console.log('');
|
|
303
|
+
log.warn(`IMPORTANT: Send USDC on ${chalk.bold('SKALE Europa')} only — not Base or Ethereum!`);
|
|
304
|
+
} else {
|
|
305
|
+
log.info(chalk.bold('To activate payments, fund this wallet from MetaMask:'));
|
|
306
|
+
console.log('');
|
|
307
|
+
log.dim(` ${chalk.white('1.')} Open MetaMask and switch to the ${chalk.bold('Base')} network`);
|
|
308
|
+
log.dim(` (Chain ID: 8453 — add it via https://chainlist.org/chain/8453)`);
|
|
309
|
+
log.dim(` ${chalk.white('2.')} Send ${chalk.bold('USDC')} to: ${chalk.hex('#34D399')(walletAddress)}`);
|
|
310
|
+
log.dim(` (Even $1 USDC is enough to start — each API call costs $0.005-$0.05)`);
|
|
311
|
+
log.dim(` ${chalk.white('3.')} Send a tiny bit of ${chalk.bold('ETH')} to the same address for gas`);
|
|
312
|
+
log.dim(` (${chalk.white('~$0.01 of ETH on Base')} is enough for hundreds of transactions)`);
|
|
313
|
+
console.log('');
|
|
314
|
+
log.warn(`IMPORTANT: Send on the ${chalk.bold('Base')} network only — not Ethereum mainnet!`);
|
|
315
|
+
}
|
|
316
|
+
log.separator();
|
|
251
317
|
} catch {
|
|
252
318
|
log.info('Wallet address will be shown when you first use the MCP server.');
|
|
253
319
|
log.dim(' Use the get_wallet_balance tool to see your address.');
|
|
@@ -312,39 +378,6 @@ export async function initCommand(options) {
|
|
|
312
378
|
}
|
|
313
379
|
}
|
|
314
380
|
}
|
|
315
|
-
|
|
316
|
-
// Network & Budget — use CLI flags as overrides
|
|
317
|
-
const configOverrides = {};
|
|
318
|
-
if (options.network) configOverrides.network = options.network;
|
|
319
|
-
if (options.budget) configOverrides.maxBudget = options.budget;
|
|
320
|
-
|
|
321
|
-
const configAnswers = await promptOrDefault([
|
|
322
|
-
{
|
|
323
|
-
type: 'list',
|
|
324
|
-
name: 'network',
|
|
325
|
-
message: 'Which network?',
|
|
326
|
-
choices: [
|
|
327
|
-
{ name: 'Base Mainnet (real USDC)', value: 'mainnet' },
|
|
328
|
-
{ name: 'Base Sepolia (testnet, free tokens for testing)', value: 'testnet' },
|
|
329
|
-
],
|
|
330
|
-
default: 'mainnet',
|
|
331
|
-
},
|
|
332
|
-
{
|
|
333
|
-
type: 'input',
|
|
334
|
-
name: 'maxBudget',
|
|
335
|
-
message: 'Max USDC budget per session (safety limit):',
|
|
336
|
-
default: '1.00',
|
|
337
|
-
validate: (v) => {
|
|
338
|
-
const n = parseFloat(v);
|
|
339
|
-
if (isNaN(n) || n <= 0) return 'Must be a positive number';
|
|
340
|
-
if (n > 100) return 'Maximum is 100 USDC per session';
|
|
341
|
-
return true;
|
|
342
|
-
},
|
|
343
|
-
},
|
|
344
|
-
], configOverrides);
|
|
345
|
-
|
|
346
|
-
network = configAnswers.network;
|
|
347
|
-
maxBudget = configAnswers.maxBudget;
|
|
348
381
|
}
|
|
349
382
|
|
|
350
383
|
console.log('');
|
|
@@ -438,17 +471,31 @@ export async function initCommand(options) {
|
|
|
438
471
|
'claude-code': 'Restart Claude Code to activate the MCP server.',
|
|
439
472
|
};
|
|
440
473
|
|
|
474
|
+
const walletLabel = walletMode === 'readonly'
|
|
475
|
+
? 'Read-only (no payments)'
|
|
476
|
+
: walletMode === 'generate'
|
|
477
|
+
? 'New wallet (needs funding)'
|
|
478
|
+
: 'Configured';
|
|
479
|
+
|
|
441
480
|
const summaryLines = [
|
|
442
481
|
`Environment: ${targetEnv.label}`,
|
|
443
482
|
`Install dir: ${installDir}`,
|
|
444
483
|
`Server: ${serverUrl}`,
|
|
445
|
-
`Network: ${network === 'mainnet' ? 'Base Mainnet' : 'Base Sepolia'}`,
|
|
484
|
+
`Network: ${network === 'mainnet' ? 'Base Mainnet' : network === 'skale' ? 'SKALE Europa' : 'Base Sepolia'}`,
|
|
446
485
|
`Budget limit: ${maxBudget} USDC / session`,
|
|
447
|
-
`Wallet: ${
|
|
486
|
+
`Wallet: ${walletLabel}`,
|
|
448
487
|
`Services: ${serviceCount > 0 ? serviceCount + ' available' : 'check with npx x402-bazaar status'}`,
|
|
449
488
|
'',
|
|
450
489
|
restartMsg[targetEnv.name] || 'Configure your AI client with the generated JSON above.',
|
|
451
490
|
'',
|
|
491
|
+
...(walletMode === 'generate' ? [
|
|
492
|
+
'Before your agent can pay for APIs:',
|
|
493
|
+
network === 'skale'
|
|
494
|
+
? ' 1. Bridge USDC to your wallet on SKALE Europa + get free sFUEL'
|
|
495
|
+
: ' 1. Send USDC + a little ETH to your wallet on Base',
|
|
496
|
+
' 2. Restart your IDE',
|
|
497
|
+
'',
|
|
498
|
+
] : []),
|
|
452
499
|
'Then try asking your agent:',
|
|
453
500
|
' "Search for weather APIs on x402 Bazaar"',
|
|
454
501
|
' "List all available services on the marketplace"',
|