x402-rails 0.1.0 → 0.2.1
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 +4 -4
- data/README.md +52 -0
- data/lib/x402/chains.rb +20 -4
- data/lib/x402/configuration.rb +2 -1
- data/lib/x402/rails/generators/templates/x402_initializer.rb +11 -0
- data/lib/x402/rails/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1bfc5a5a404b98b156b9c8ad7d833787e5f082eff1b5d5b95e18663a1cb64fc8
|
|
4
|
+
data.tar.gz: 0bda82b7d122d5b6fbbe6278db1dcd19efda67a6418ee2d8d6a23fb74ecd55fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 88f0a27e97ee07b7ae746d7e0ecef9c8676bd8b40544fadead68f6eae5d57b5e318c73edf03645d97670ce197334b596e086d948e92c711ad7fe488f2a1666df
|
|
7
|
+
data.tar.gz: c5647b5c8ce65f3bbdd2dde221afbd2a27240d77e12ba2f6e0c1387a1b046e170efbdbf5288898cc5b670ea9ee615d92f579e28d4f78b86558787ad5d90ebe77
|
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://
|
|
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://
|
|
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://
|
|
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://
|
|
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
|
data/lib/x402/configuration.rb
CHANGED
|
@@ -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
|
data/lib/x402/rails/version.rb
CHANGED
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
|
|
4
|
+
version: 0.2.1
|
|
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-
|
|
11
|
+
date: 2025-10-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -123,13 +123,13 @@ 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.
|
|
127
|
-
networks.
|
|
126
|
+
x402 protocol.
|
|
128
127
|
email:
|
|
129
|
-
- zach@quiknode.io
|
|
128
|
+
- zach+x402@quiknode.io
|
|
130
129
|
executables: []
|
|
131
130
|
extensions: []
|
|
132
|
-
extra_rdoc_files:
|
|
131
|
+
extra_rdoc_files:
|
|
132
|
+
- README.md
|
|
133
133
|
files:
|
|
134
134
|
- ".rspec"
|
|
135
135
|
- LICENSE.txt
|
|
@@ -156,6 +156,7 @@ licenses:
|
|
|
156
156
|
metadata:
|
|
157
157
|
homepage_uri: https://github.com/quiknode-labs/x402-rails
|
|
158
158
|
source_code_uri: https://github.com/quiknode-labs/x402-rails
|
|
159
|
+
documentation_uri: https://github.com/quiknode-labs/x402-rails#readme
|
|
159
160
|
post_install_message:
|
|
160
161
|
rdoc_options: []
|
|
161
162
|
require_paths:
|