Quickstart

Build with Agent#

After installing the payment Skill for your Agent, it can recognize 402 payment requests, sign transactions, and complete payments without human intervention.

Configuration#

Send the following prompt to the AI to install Onchain OS Skills and configure an Agentic Wallet for your Agent:

Run npx skills add okx/onchainos-skills to install Onchain OS skills
Note: Please install to the skill directory corresponding to the current Agent
Also, help me install the latest version of the CLI based on this documentation [GitHub - okx/onchainos-skills: Skills for AI agents to integrate with the OKX OnchainOS API — Wallet](https://github.com/okx/onchainos-skills)

Verification#

The following example uses "query weather" as a demonstration. Please test with an actual online x402 paid service as needed.

Log in:

Shell
onchainos wallet login

Request the seller's service/resource:

Javascript
// Not a production service, for reference only
Access the service at http://localhost:4021/weather

If payment information is returned, the request was successful:

The service returned an x402 payment requirement response (HTTP 402). Details:

  - x402 Version: 2
  - Resource: /weather — Get current weather data for any location, returns application/json
  - Payment methods (two schemes):
    - exact — One-time payment
    - aggr_deferred — Deferred payment
  - Network: eip155:196 (OKX X Layer)
  - Token: USD₮0 (0x779ded0c9e1022225f8e0630b35a9b54be713736)
  - Amount: 1000 (smallest unit)
  - Pay to: 0xb483abdb92f8061e9a3a082a4aaaa6b88c381308
  - Timeout: 600,000 seconds

  This endpoint requires payment via the x402 protocol to access. Would you like me to initiate payment to get the weather data?

Confirm the payment, sign the transaction data, and replay the request to the seller:

Signature successful, replaying request:
Bash(PAYMENT_PAYLOAD=$(python3 -c "
      import json, base64
      payload = {
          'x402Version': 2,
          'resource': {'url': '/weather', 'description': 'Get current weather data for any location', 'mimeType':
      'application/json'},
          'accepted': {'scheme': 'exact', 'network': 'eip155:196', 'asset':
      '0x779ded0...4be713736', 'amount': '1000', 'payTo':
      '0xb483abd....aa6b88c381308', 'maxTimeoutSeconds': 600000, 'extra': {'name': 'USD₮0',
      'version': '1'}},
          'payload': {
              'signature': '0x3d1907a6ba9f592c...35868ea11b',
              'authorization': {'from': '0xbda9fde...99763', 'nonce':
              '0x20862cc...06e48', 'to':
              '0xb483abd...81308', 'validAfter': '0', 'validBefore': '1775837508', 'value': '1000'}
          }
      }
      print(base64.b64encode(json.dumps(payload, separators=(',', ':')).encode()).decode())
      ")
      curl -s -D - http://localhost:4021/weather -H "PAYMENT-SIGNATURE: $PAYMENT_PAYLOAD")
  ⎿  HTTP/1.1 200 OK

The resource returned by the seller is received:

⏺ Payment successful! Weather data returned:

  {"report": {"temperature": 70, "weather": "sunny"}}

  - Temperature: 70°F
  - Weather: Sunny ☀️
Table of contents