@@ -10,6 +10,7 @@ import (
1010 "strconv"
1111 "time"
1212
13+ "github.com/ethereum/go-ethereum/ethclient"
1314 "github.com/joho/godotenv"
1415 x402 "github.com/x402-foundation/x402/go"
1516 x402http "github.com/x402-foundation/x402/go/http"
@@ -34,13 +35,25 @@ func main() {
3435 endpointPath := envOr ("ENDPOINT_PATH" , "/api/generate" )
3536 url := baseURL + endpointPath
3637
38+ rpcURL := envOr ("EVM_RPC_URL" , "https://sepolia.base.org" )
3739 channelSalt := envOr ("CHANNEL_SALT" , batchedclient .DefaultSalt )
3840 storageDir := os .Getenv ("STORAGE_DIR" )
3941 numberOfRequests := atoiOr ("NUMBER_OF_REQUESTS" , 3 )
4042 refundAfterRequests := os .Getenv ("REFUND_AFTER_REQUESTS" ) == "true"
4143 refundAmount := os .Getenv ("REFUND_AMOUNT" )
4244
43- signer , err := evmsigners .NewClientSignerFromPrivateKey (evmPrivateKey )
45+ // Dial an RPC client so the signer can read on-chain channel state when
46+ // local storage is cold. Without this, a fresh client run against a channel
47+ // that already has on-chain totalClaimed would sign vouchers with a stale
48+ // cumulative base and the facilitator would reject them.
49+ ethClient , err := ethclient .Dial (rpcURL )
50+ if err != nil {
51+ fmt .Printf ("Failed to dial EVM RPC %s: %v\n " , rpcURL , err )
52+ os .Exit (1 )
53+ }
54+ defer ethClient .Close ()
55+
56+ signer , err := evmsigners .NewClientSignerFromPrivateKeyWithClient (evmPrivateKey , ethClient )
4457 if err != nil {
4558 fmt .Printf ("Failed to create signer: %v\n " , err )
4659 os .Exit (1 )
@@ -95,11 +108,18 @@ func main() {
95108 os .Exit (1 )
96109 }
97110
98- body , _ := readJSON (resp )
99- fmt .Printf ("Request %d — RESPONSE\n %s\n " , i + 1 , indent (body ))
111+ fmt .Printf ("Request %d — %s\n " , i + 1 , resp .Status )
112+ body , errBody := readJSON (resp )
113+ if errBody != nil {
114+ fmt .Printf (" body: <not JSON: %v>\n " , errBody )
115+ } else {
116+ fmt .Printf ("Request %d — RESPONSE\n %s\n " , i + 1 , indent (body ))
117+ }
100118
101119 if settle , _ := extractSettleResponse (resp ); settle != nil {
102120 fmt .Println (indent (settle ))
121+ } else if resp .StatusCode != http .StatusOK {
122+ fmt .Printf (" no PAYMENT-RESPONSE (%s) — payment did not settle\n " , resp .Status )
103123 }
104124
105125 _ = resp .Body .Close ()
0 commit comments