x402-rails 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 411abe38109c401d64e94078fd5b69bb3937b78e7bb6b1518921897ca28ad904
4
- data.tar.gz: 2fe5f74f481df1a9b2e74cbd268ad02033d5250f9624eeb7a4912742409a53a5
3
+ metadata.gz: 5eb22e620dbc76790e135e60d6b80ea31eeb39d3ae89f1398e9c80888382a91c
4
+ data.tar.gz: 59d33e7a75003384fe74799d93b6c4b6d977b589f7c3918cc7df8f742a1b71c4
5
5
  SHA512:
6
- metadata.gz: f1bbcaee8f5a30a99fb857f9983bc6ec638d9a6f10c2651e14ab65e3bb68bd4087fac81c5c2db25b1cabd1c92209cb6754a82b369e9f76dbf21998a43cf303c3
7
- data.tar.gz: ac5aa6785d6cf1a9284cd4ac776200199d7c53696ae462c3775e226218727be30cbc2acabd39329aec6d8ec6918805fd52b609cddd185262d159b46856817da8
6
+ metadata.gz: 935b9f9445d18a39900c94ea8272bd86c492f0a79041baad0a2d0b4c1bd9b9a687e23fe1fb7b97d55168ae872cfc058bc7d2c5ce765030133da3a4d1100f359e
7
+ data.tar.gz: 0f286a2011822994b1b1407f13c9dfd9905ba1672d2c0780e440f0825b2b84ad6eaf66c2e6ee1284b7f74dc31cf0c6b3f8514cc34bc4249448eaf842d22f8c04
data/README.md CHANGED
@@ -17,6 +17,10 @@ Supports Base, avalanche, and other blockchain networks.
17
17
  - **Browser paywall** and API support
18
18
  - **Rails 7.0+** compatible
19
19
 
20
+ ## Example Video
21
+
22
+ https://github.com/user-attachments/assets/05983bb3-7422-4c06-97ab-2fb53d6428cc
23
+
20
24
  ## Installation
21
25
 
22
26
  Add to your Gemfile:
@@ -155,6 +159,48 @@ end
155
159
  | `chain` | No | `"base-sepolia"` | Blockchain network to use (`base-sepolia`, `base`, `avalanche-fuji`, `avalanche`) |
156
160
  | `currency` | No | `"USDC"` | Payment token symbol (currently only USDC supported) |
157
161
  | `optimistic` | No | `true` | Settlement mode (see Optimistic vs Non-Optimistic Mode below) |
162
+ | `rpc_urls` | No | `{}` | Custom RPC endpoint URLs per chain (see Custom RPC URLs below) |
163
+
164
+ ### Custom RPC URLs
165
+
166
+ By default, x402-rails uses public QuickNode RPC endpoints for each supported chain. For production use or higher reliability, you can configure custom RPC URLs from providers like [QuickNode](https://www.quicknode.com/).
167
+
168
+ **Configuration Priority** (highest to lowest):
169
+
170
+ 1. Programmatic configuration via `config.rpc_urls`
171
+ 2. Per-chain environment variables
172
+ 3. Built-in default RPC URLs
173
+
174
+ #### Method 1: Programmatic Configuration
175
+
176
+ Configure RPC URLs in your initializer:
177
+
178
+ ```ruby
179
+ X402.configure do |config|
180
+ config.wallet_address = ENV['X402_WALLET_ADDRESS']
181
+
182
+ # Custom RPC URLs per chain
183
+ config.rpc_urls["base"] = "https://your-base-rpc.quiknode.pro/your-key"
184
+ config.rpc_urls["base-sepolia"] = "https://your-sepolia-rpc.quiknode.pro/your-key"
185
+ config.rpc_urls["avalanche"] = "https://your-avalanche-rpc.quiknode.pro/your-key"
186
+ end
187
+ ```
188
+
189
+ #### Method 2: Environment Variables
190
+
191
+ Set per-chain environment variables:
192
+
193
+ ```bash
194
+ # Per-chain RPC URL overrides
195
+ X402_BASE_RPC_URL=https://your-base-rpc.quiknode.pro/your-key
196
+ X402_BASE_SEPOLIA_RPC_URL=https://your-sepolia-rpc.quiknode.pro/your-key
197
+ X402_AVALANCHE_RPC_URL=https://your-avalanche-rpc.quiknode.pro/your-key
198
+ X402_AVALANCHE_FUJI_RPC_URL=https://your-fuji-rpc.quiknode.pro/your-key
199
+ ```
200
+
201
+ #### Method 3: Default RPC URLs
202
+
203
+ If no custom RPC URL is configured, it will default to the public QuickNode RPC urls.
158
204
 
159
205
  ## Environment Variables
160
206
 
@@ -169,6 +215,12 @@ X402_FACILITATOR_URL=https://x402.org/facilitator
169
215
  X402_CHAIN=base-sepolia
170
216
  X402_CURRENCY=USDC
171
217
  X402_OPTIMISTIC=true # "true" or "false"
218
+
219
+ # Custom RPC URLs (optional, per-chain overrides)
220
+ X402_BASE_RPC_URL=https://your-base-rpc.quiknode.pro/your-key
221
+ X402_BASE_SEPOLIA_RPC_URL=https://your-base-speoliarpc.quiknode.pro/your-key
222
+ X402_AVALANCHE_RPC_URL=https://your-avalanche.quiknode.pro/your-key
223
+ X402_AVALANCHE_FUJI_RPC_URL=https://your-fuji-rpc.quiknode.pro/your-key
172
224
  ```
173
225
 
174
226
  ## Examples
data/lib/x402/chains.rb CHANGED
@@ -5,25 +5,25 @@ module X402
5
5
  CHAINS = {
6
6
  "base-sepolia" => {
7
7
  chain_id: 84532,
8
- rpc_url: "https://sepolia.base.org",
8
+ rpc_url: "https://clean-snowy-hexagon.base-sepolia.quiknode.pro",
9
9
  usdc_address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
10
10
  explorer_url: "https://sepolia.basescan.org"
11
11
  },
12
12
  "base" => {
13
13
  chain_id: 8453,
14
- rpc_url: "https://mainnet.base.org",
14
+ rpc_url: "https://snowy-compatible-ensemble.base-mainnet.quiknode.pro",
15
15
  usdc_address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
16
16
  explorer_url: "https://basescan.org"
17
17
  },
18
18
  "avalanche-fuji" => {
19
19
  chain_id: 43113,
20
- rpc_url: "https://api.avax-test.network/ext/bc/C/rpc",
20
+ rpc_url: "https://muddy-sly-field.avalanche-testnet.quiknode.pro/ext/bc/C/rpc",
21
21
  usdc_address: "0x5425890298aed601595a70AB815c96711a31Bc65",
22
22
  explorer_url: "https://testnet.snowtrace.io"
23
23
  },
24
24
  "avalanche" => {
25
25
  chain_id: 43114,
26
- rpc_url: "https://api.avax.network/ext/bc/C/rpc",
26
+ rpc_url: "https://floral-patient-panorama.avalanche-mainnet.quiknode.pro/ext/bc/C/rpc",
27
27
  usdc_address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
28
28
  explorer_url: "https://snowtrace.io"
29
29
  }
@@ -77,5 +77,21 @@ module X402
77
77
  def currency_decimals_for_chain(chain_name)
78
78
  currency_config_for_chain(chain_name)[:decimals]
79
79
  end
80
+
81
+ def rpc_url_for(chain_name)
82
+ # Priority: 1) Programmatic config, 2) ENV variable, 3) Default from CHAINS
83
+ config = X402.configuration
84
+
85
+ # Check programmatic configuration
86
+ return config.rpc_urls[chain_name] if config.rpc_urls[chain_name]
87
+
88
+ # Check environment variable
89
+ env_var_name = "X402_#{chain_name.upcase.gsub('-', '_')}_RPC_URL"
90
+ env_rpc = ENV[env_var_name]
91
+ return env_rpc if env_rpc && !env_rpc.empty?
92
+
93
+ # Fall back to default
94
+ chain_config(chain_name)[:rpc_url]
95
+ end
80
96
  end
81
97
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module X402
4
4
  class Configuration
5
- attr_accessor :wallet_address, :facilitator, :chain, :currency, :optimistic
5
+ attr_accessor :wallet_address, :facilitator, :chain, :currency, :optimistic, :rpc_urls
6
6
 
7
7
  def initialize
8
8
  @wallet_address = ENV.fetch("X402_WALLET_ADDRESS", nil)
@@ -10,6 +10,7 @@ module X402
10
10
  @chain = ENV.fetch("X402_CHAIN", "base-sepolia")
11
11
  @currency = ENV.fetch("X402_CURRENCY", "USDC")
12
12
  @optimistic = ENV.fetch("X402_OPTIMISTIC", "false") == "true" # Default to optimistic mode (fast response, settle after)
13
+ @rpc_urls = {}
13
14
  end
14
15
 
15
16
  def validate!
@@ -19,6 +19,17 @@ X402.configure do |config|
19
19
 
20
20
  # Currency symbol (currently only USDC is supported)
21
21
  config.currency = ENV.fetch("X402_CURRENCY", "USDC")
22
+
23
+ # Custom RPC URLs (optional)
24
+ # Use custom RPC endpoints from providers like QuickNode, Alchemy, or Infura
25
+ # for better reliability and rate limits. Uncomment and configure as needed:
26
+ #
27
+ # config.rpc_urls["base"] = "https://your-base-rpc.quiknode.pro/your-key"
28
+ # config.rpc_urls["base-sepolia"] = "https://your-sepolia-rpc.quiknode.pro/your-key"
29
+ # config.rpc_urls["avalanche"] = "https://your-avalanche-rpc.quiknode.pro/your-key"
30
+ #
31
+ # Or use environment variables (see README.md for details):
32
+ # X402_BASE_RPC_URL, X402_BASE_SEPOLIA_RPC_URL, etc.
22
33
  end
23
34
 
24
35
  # Validate configuration on initialization
@@ -2,6 +2,6 @@
2
2
 
3
3
  module X402
4
4
  module Rails
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: x402-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - QuickNode
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-10-29 00:00:00.000000000 Z
11
+ date: 2025-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -123,10 +123,9 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '6.0'
125
125
  description: Accept instant blockchain micropayments in Rails applications using the
126
- x402 protocol. Enable HTTP 402 Payment Required with USDC payments on Base and other
127
- networks.
126
+ x402 protocol.
128
127
  email:
129
- - zach@quiknode.io
128
+ - zach+x402@quiknode.io
130
129
  executables: []
131
130
  extensions: []
132
131
  extra_rdoc_files: []