Example Flows

Example Flows

Complete code examples for common use cases.


Setup

Dependencies

npm install viem

Configuration

import { createWalletClient, http, keccak256, toHex } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { base } from 'viem/chains';

const GATEWAY_URL = 'https://x402.quickintel.io';
const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY;
const PROVIDER_NAME = 'my-trading-agent';

const account = privateKeyToAccount(PRIVATE_KEY);
const walletClient = createWalletClient({
  account,
  chain: base,
  transport: http()
});

Pricing Reminder

Call Type
Cost

Any /v1/tator/prompt call

$0.20

Job polling (/v1/tator/jobs/:id)

Free

⚠️ You are charged $0.20 per call regardless of outcome. Validate prompts before sending.


Example 1: Price Check (Info Query)

A simple informational query that doesn't require signing any transactions.


Example 2: Buy Token

Execute a token purchase and sign the resulting transaction.


Example 3: Swap Tokens

Swap between two tokens.


Example 4: Bridge Assets

Bridge tokens between chains.


Example 5: Async Mode (Long Operations)

Use async mode for operations that may take longer.


Example 6: Validate Prompt Before Sending

Avoid wasting $0.20 on unclear prompts by validating first.


Example 7: Token Safety Check

Check if a token is safe before trading.


Helper Functions

Sign x402 Payment ($0.20)

Submit Prompt with Payment

Sleep Helper


Error Handling


Full Working Example


Cost Summary

Operation
API Cost
Notes

Price check

$0.20

Info response

Token scan

$0.20

Info response

Buy/Sell/Swap

$0.20

Returns unsigned tx

Bridge

$0.20

Returns unsigned tx

Unclear prompt

$0.20

Returns clarification

Error

$0.20

Still charged

Job polling

Free

Poll as needed


Next Steps

Last updated