|
|
|
|
@ -1,4 +1,3 @@
|
|
|
|
|
from x402.client import X402Client
|
|
|
|
|
from eth_account import Account
|
|
|
|
|
from x402.clients.httpx import x402HttpxClient
|
|
|
|
|
|
|
|
|
|
@ -10,8 +9,7 @@ load_dotenv()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def buy_x402_service(
|
|
|
|
|
base_url: str = None,
|
|
|
|
|
endpoint: str = None
|
|
|
|
|
base_url: str = None, endpoint: str = None
|
|
|
|
|
):
|
|
|
|
|
"""
|
|
|
|
|
Purchase a service from the X402 bazaar using the provided affordable_service details.
|
|
|
|
|
@ -38,12 +36,14 @@ async def buy_x402_service(
|
|
|
|
|
print(await response.aread())
|
|
|
|
|
```
|
|
|
|
|
"""
|
|
|
|
|
key = os.getenv('X402_PRIVATE_KEY')
|
|
|
|
|
key = os.getenv("X402_PRIVATE_KEY")
|
|
|
|
|
|
|
|
|
|
# Set up your payment account from private 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)
|
|
|
|
|
print(await response.aread())
|
|
|
|
|
|
|
|
|
|
|