move examples

pull/1206/head
Kye Gomez 1 day ago
parent 50b43693b9
commit 88eaeeda58

@ -1,4 +1,3 @@
from x402.client import X402Client
from eth_account import Account from eth_account import Account
from x402.clients.httpx import x402HttpxClient from x402.clients.httpx import x402HttpxClient
@ -10,8 +9,7 @@ load_dotenv()
async def buy_x402_service( async def buy_x402_service(
base_url: str = None, base_url: str = None, endpoint: str = None
endpoint: str = None
): ):
""" """
Purchase a service from the X402 bazaar using the provided affordable_service details. Purchase a service from the X402 bazaar using the provided affordable_service details.
@ -31,20 +29,22 @@ async def buy_x402_service(
```python ```python
affordable_service = {"id": "service123", "price": 90000} affordable_service = {"id": "service123", "price": 90000}
response = await buy_x402_service( response = await buy_x402_service(
affordable_service, affordable_service,
base_url="https://api.cdp.coinbase.com", base_url="https://api.cdp.coinbase.com",
endpoint="/x402/v1/bazaar/services/service123" endpoint="/x402/v1/bazaar/services/service123"
) )
print(await response.aread()) print(await response.aread())
``` ```
""" """
key = os.getenv('X402_PRIVATE_KEY') key = os.getenv("X402_PRIVATE_KEY")
# Set up your payment account from private key # Set up your payment account from private key
account = Account.from_key(key) account = Account.from_key(key)
async with x402HttpxClient(account=account, base_url=base_url) as client: async with x402HttpxClient(
account=account, base_url=base_url
) as client:
response = await client.get(endpoint) response = await client.get(endpoint)
print(await response.aread()) print(await response.aread())
return response return response

@ -4,7 +4,6 @@ from swarms import Agent
import httpx import httpx
async def query_x402_services( async def query_x402_services(
limit: Optional[int] = None, limit: Optional[int] = None,
max_price: Optional[int] = None, max_price: Optional[int] = None,
@ -207,7 +206,6 @@ def get_x402_services_sync(
return str(services) return str(services)
agent = Agent( agent = Agent(
agent_name="X402-Discovery-Agent", agent_name="X402-Discovery-Agent",
agent_description="A agent that queries the x402 discovery services from the Coinbase CDP API.", agent_description="A agent that queries the x402 discovery services from the Coinbase CDP API.",
@ -228,4 +226,4 @@ if __name__ == "__main__":
out = agent.run( out = agent.run(
task="Summarize the first 10 services under 100000 atomic units (e.g., $0.10 USDC)" task="Summarize the first 10 services under 100000 atomic units (e.g., $0.10 USDC)"
) )
print(out) print(out)

@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry] [tool.poetry]
name = "swarms" name = "swarms"
version = "8.6.1" version = "8.6.2"
description = "Swarms - TGSC" description = "Swarms - TGSC"
license = "MIT" license = "MIT"
authors = ["Kye Gomez <kye@swarms.world>"] authors = ["Kye Gomez <kye@swarms.world>"]

Loading…
Cancel
Save