这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_product_details_and_request_payment(self, product_name: str) -> dict:
price = self._get_product_price(product_name)
requirements = PaymentRequirements(
scheme="exact",
network="base-sepolia",
network="eip155:84532", # Base Sepolia testnet
asset="0x036CbD53842c5426634e7929541eC2318f3dCF7e",
pay_to=self._wallet_address,
max_amount_required=price,
Expand Down
10 changes: 5 additions & 5 deletions python/x402_a2a/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class x402ServerConfig(BaseModel):
"""Configuration for how a server expects to be paid"""
price: Union[str, int, TokenAmount] # Payment price (Money or TokenAmount)
pay_to_address: str # Ethereum address to receive payment
network: str = "base" # Blockchain network
network: str = "eip155:8453" # Blockchain network (CAIP-2 format, Base mainnet)
description: str = "Payment required..." # Human-readable description
mime_type: str = "application/json" # Expected response type
max_timeout_seconds: int = 600 # Payment validity timeout
Expand Down Expand Up @@ -383,7 +383,7 @@ def create_payment_requirements(
price: Union[str, int, TokenAmount], # Price can be Money or TokenAmount
pay_to_address: str,
resource: str,
network: str = "base",
network: str = "eip155:8453",
description: str = "",
mime_type: str = "application/json",
scheme: str = "exact",
Expand Down Expand Up @@ -808,7 +808,7 @@ async def handle_payment_request(task: Task, price: str, resource: str):
price=price, # Can be "$1.00", 1.00, or TokenAmount
pay_to_address="0x...", # Merchant's address
resource=resource,
network="base",
network="eip155:8453",
description="Service payment"
)

Expand Down Expand Up @@ -837,7 +837,7 @@ async def handle_payment_submission(task: Task, payment_requirements: PaymentReq
if not verify_response.is_valid:
task = utils.record_payment_failure(
task, "verification_failed",
SettleResponse(success=False, network="base", error_reason=verify_response.invalid_reason)
SettleResponse(success=False, network="eip155:8453", error_reason=verify_response.invalid_reason)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The network is hardcoded to "eip155:8453" (Base mainnet) in this failure case. This is incorrect if the payment was intended for a different network. You should use the network from the payment_requirements object, which is available in this function's scope.

Suggested change
SettleResponse(success=False, network="eip155:8453", error_reason=verify_response.invalid_reason)
SettleResponse(success=False, network=payment_requirements.network, error_reason=verify_response.invalid_reason)

)
return task

Expand All @@ -851,7 +851,7 @@ async def handle_payment_submission(task: Task, payment_requirements: PaymentReq
settle_response_result = SettleResponse(
success=settle_response.success,
transaction=settle_response.transaction,
network=settle_response.network or "base",
network=settle_response.network or "eip155:8453",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The fallback network is hardcoded to "eip155:8453" (Base mainnet). If settle_response.network is None, it's safer to fall back to the network specified in the original payment_requirements rather than assuming Base mainnet.

Suggested change
network=settle_response.network or "eip155:8453",
network=settle_response.network or payment_requirements.network,

payer=settle_response.payer,
error_reason=settle_response.error_reason
)
Expand Down
25 changes: 13 additions & 12 deletions python/x402_a2a/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def require_payment(
price: Union[str, int, TokenAmount],
pay_to_address: str,
resource: Optional[str] = None,
network: str = "base",
network: str = "eip155:8453",
description: str = "Payment required for this service",
message: Optional[str] = None,
) -> x402PaymentRequiredException:
Expand All @@ -34,9 +34,10 @@ def require_payment(

Args:
price: Payment amount (e.g., "$1.00", 1.00, TokenAmount)
pay_to_address: Ethereum address to receive payment
pay_to_address: Address to receive payment (format depends on network)
resource: Resource identifier (auto-generated if None)
network: Blockchain network (default: "base")
network: Blockchain network in CAIP-2 format (default: "eip155:8453" for Base).
Examples: "eip155:1" (Ethereum), "bip122:000000000019d6689c085ae165831e93" (Bitcoin)
description: Human-readable description
message: Exception message (default: uses description)

Expand Down Expand Up @@ -98,16 +99,16 @@ def paid_service(
price: Union[str, int, TokenAmount],
pay_to_address: str,
resource: Optional[str] = None,
network: str = "base",
network: str = "eip155:8453",
description: str = "Payment required for this service",
):
"""Decorator to automatically require payment for a function or method.

Args:
price: Payment amount (e.g., "$1.00", 1.00, TokenAmount)
pay_to_address: Ethereum address to receive payment
pay_to_address: Address to receive payment (format depends on network)
resource: Resource identifier (auto-generated from function name if None)
network: Blockchain network (default: "base")
network: Blockchain network in CAIP-2 format (default: "eip155:8453" for Base)
description: Human-readable description

Example:
Expand Down Expand Up @@ -149,16 +150,16 @@ def create_tiered_payment_options(
pay_to_address: str,
resource: str,
tiers: Optional[List[dict]] = None,
network: str = "base",
network: str = "eip155:8453",
) -> List[PaymentRequirements]:
"""Create multiple payment options with different tiers/features.

Args:
base_price: Base payment amount
pay_to_address: Ethereum address to receive payment
pay_to_address: Address to receive payment (format depends on network)
resource: Base resource identifier
tiers: List of tier definitions with 'multiplier', 'suffix', 'description'
network: Blockchain network (default: "base")
network: Blockchain network in CAIP-2 format (default: "eip155:8453" for Base)

Returns:
List of PaymentRequirements for different service tiers
Expand Down Expand Up @@ -246,7 +247,7 @@ def smart_paid_service(
price: Union[str, int, TokenAmount],
pay_to_address: str,
resource: Optional[str] = None,
network: str = "base",
network: str = "eip155:8453",
description: str = "Payment required for this service",
):
"""Smart decorator that only requires payment if not already paid.
Expand All @@ -256,9 +257,9 @@ def smart_paid_service(

Args:
price: Payment amount (e.g., "$1.00", 1.00, TokenAmount)
pay_to_address: Ethereum address to receive payment
pay_to_address: Address to receive payment (format depends on network)
resource: Resource identifier (auto-generated from function name if None)
network: Blockchain network (default: "base")
network: Blockchain network in CAIP-2 format (default: "eip155:8453" for Base)
description: Human-readable description

Example:
Expand Down
11 changes: 7 additions & 4 deletions python/x402_a2a/core/merchant.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create_payment_requirements(
price: Price,
pay_to_address: str,
resource: str,
network: str = "base",
network: str = "eip155:8453",
description: str = "",
mime_type: str = "application/json",
scheme: str = "exact",
Expand All @@ -37,10 +37,13 @@ def create_payment_requirements(
price: Payment price. Can be:
- Money: USD amount as string/int (e.g., "$3.10", 0.10, "0.001") - defaults to USDC
- TokenAmount: Custom token amount with asset information
pay_to_address: Ethereum address to receive the payment
pay_to_address: Address to receive the payment (format depends on network)
resource: Resource identifier (e.g., "/generate-image")
network: Blockchain network (default: "base")
description: Human-readable description
network: Blockchain network in CAIP-2 format (default: "eip155:8453" for Base)
Examples:
- EVM chains: "eip155:1" (Ethereum), "eip155:8453" (Base), "eip155:137" (Polygon)
- Bitcoin: "bip122:000000000019d6689c085ae165831e93" (mainnet)
- Solana: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp" (mainnet) description: Human-readable description
mime_type: Expected response content type
scheme: Payment scheme (default: "exact")
max_timeout_seconds: Payment validity timeout
Expand Down
2 changes: 1 addition & 1 deletion python/x402_a2a/executors/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async def _auto_pay(self, task, event_queue: EventQueue):
from ..types import SettleResponse, x402ErrorCode

failure_response = SettleResponse(
success=False, network="base", error_reason=f"Payment failed: {e}"
success=False, network="eip155:8453", error_reason=f"Payment failed: {e}"
)
task = self.utils.record_payment_failure(
task, x402ErrorCode.INVALID_SIGNATURE, failure_response
Expand Down
2 changes: 1 addition & 1 deletion python/x402_a2a/executors/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ async def _fail_payment(
):
"""Handle payment failure."""
failure_response = SettleResponse(
success=False, network="base", error_reason=error_reason
success=False, network="eip155:8453", error_reason=error_reason
)
task = self.utils.record_payment_failure(task, error_code, failure_response)

Expand Down
2 changes: 1 addition & 1 deletion python/x402_a2a/types/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class x402ServerConfig(BaseModel):

price: Union[str, int, TokenAmount]
pay_to_address: str
network: str = "base"
network: str = "eip155:8453" # Base network in CAIP-2 format
description: str = "Payment required..."
mime_type: str = "application/json"
max_timeout_seconds: int = 600
Expand Down
6 changes: 3 additions & 3 deletions python/x402_a2a/types/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def for_service(
price: Union[str, int, TokenAmount],
pay_to_address: str,
resource: str,
network: str = "base",
network: str = "eip155:8453",
description: str = "Payment required for this service",
message: Optional[str] = None,
) -> "x402PaymentRequiredException":
Expand All @@ -122,9 +122,9 @@ def for_service(

Args:
price: Payment amount (e.g., "$1.00", 1.00, TokenAmount)
pay_to_address: Ethereum address to receive payment
pay_to_address: Address to receive payment (format depends on network)
resource: Resource identifier (e.g., "/api/generate")
network: Blockchain network (default: "base")
network: Blockchain network in CAIP-2 format (default: "eip155:8453" for Base)
description: Human-readable description
message: Exception message (default: uses description)

Expand Down
6 changes: 3 additions & 3 deletions spec/v0.1/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ When a Client Agent requests a service, the Merchant Agent determines that payme
"x402Version": 1,
"accepts": [{
"scheme": "exact",
"network": "base",
"network": "eip155:8453",
"resource": "https://api.example.com/generate-image",
"description": "Generate an image",
"mimeType": "application/json",
Expand Down Expand Up @@ -202,7 +202,7 @@ The Agent **MUST** include ALL payment receipts created in the lifetime of a Tas
"x402.payment.receipts": [{
"success": true,
"transaction": "0xabc123...",
"network": "base",
"network": "eip155:8453",
"payer": "0xpayerAddress"
}]
}
Expand Down Expand Up @@ -338,7 +338,7 @@ The management of Task states at payment failure is at the discretion of the Mer
"x402.payment.receipts": [{
"success": false,
"errorReason": "Payment authorization was submitted after its 'validBefore' timestamp.",
"network": "base",
"network": "eip155:8453",
"transaction": ""
}]
}
Expand Down
Loading