Skip to content

Commit b159e7c

Browse files
committed
Gateway config updates
1 parent dac5e45 commit b159e7c

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

docs/pages/fund-agents-apps/run-gateway.mdx

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,11 @@ You can provide the configuration options for your XMTP Gateway Service either d
159159
| Name | Required | Command line flag | Environment variable | Info |
160160
| ------------------------ | -------- | -------------------------------------- | -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
161161
| Payer Private Key | `true` | `--payer.private-key` | `XMTPD_PAYER_PRIVATE_KEY` | The `secp256k1` private key of the Ethereum Account you have already funded in the Funding Portal. Used to sign transactions and pay fees from your payer allowance in the Payer Registry smart contract. |
162+
| App Chain RPC URL | `true` | `--contracts.app-chain.rpc-url` | `XMTPD_APP_CHAIN_RPC_URL` | The RPC URL of your Blockchain RPC provider's endpoint for XMTP Chain |
163+
| Settlement Chain RPC URL | `true` | `--contracts.settlement-chain.rpc-url` | `XMTPD_SETTLEMENT_CHAIN_RPC_URL` | The RPC URL of your Blockchain RPC provider's endpoint for the Base chain |
162164
| App Chain WSS URL | `true` | `--contracts.app-chain.wss-url` | `XMTPD_APP_CHAIN_WSS_URL` | The websocket URL of your Blockchain RPC provider's endpoint for XMTP Chain |
163165
| Settlement Chain WSS URL | `true` | `--contracts.settlement-chain.wss-url` | `XMTPD_SETTLEMENT_CHAIN_WSS_URL` | The websocket URL of your Blockchain RPC provider's endpoint for the Base chain |
164-
| Environment | `true` | `--contracts.environment` | `XMTPD_CONTRACTS_ENVIRONMENT` | The environment your XMTP Gateway Service will run in. Valid values are `local`, `testnet`, and `mainnet` |
165-
| Enable Redis | `true` | `--redis.enable` | `XMTPD_REDIS_ENABLE` | Use Redis for nonce management and rate limiting. |
166+
| Environment | `true` | `--contracts.environment` | `XMTPD_CONTRACTS_ENVIRONMENT` | The environment your XMTP Gateway Service will run in. Valid values are `anvil`, `testnet`, and `mainnet` |
166167
| Redis Connection String | `false` | `--redis.connection-string` | `XMTPD_REDIS_CONNECTION_STRING` | The connection string for your Redis instance |
167168

168169
</div>
@@ -392,6 +393,48 @@ func main() {
392393

393394
```
394395

396+
```go [Rate Limiting]
397+
package main
398+
399+
import (
400+
"context"
401+
"log"
402+
"time"
403+
404+
"github.com/xmtp/xmtpd/pkg/gateway"
405+
"github.com/xmtp/xmtpd/pkg/gateway/authorizers"
406+
)
407+
408+
func main() {
409+
cfg := gateway.MustLoadConfig()
410+
redis := gateway.MustSetupRedisClient(context.Background(), cfg.Redis)
411+
412+
authorizer := authorizers.NewRateLimitBuilder().
413+
WithLogger(gateway.MustCreateLogger(cfg)).
414+
WithRedis(redis).
415+
// Set rate limits to 50 requests/minute and 250 requests/hour
416+
WithLimits(authorizers.RateLimit{
417+
Capacity: 50,
418+
RefillEvery: time.Minute,
419+
}, authorizers.RateLimit{
420+
Capacity: 250,
421+
RefillEvery: time.Hour,
422+
}).
423+
MustBuild()
424+
425+
gatewayService, err := gateway.NewGatewayServiceBuilder(cfg).
426+
WithRedisClient(redis).
427+
WithAuthorizers(authorizer).
428+
Build()
429+
if err != nil {
430+
log.Fatalf("Failed to build gateway service: %v", err)
431+
}
432+
433+
gatewayService.WaitForShutdown()
434+
}
435+
436+
```
437+
395438
:::
396439

397440
## Authorize requests
@@ -443,7 +486,7 @@ We provide a Docker image that corresponds to the bare bones example above that
443486
docker run -p 5050:5050 -p 5055:5055 -e XMTPD_PAYER_PRIVATE_KEY=... xmtp/xmtpd-gateway:main
444487
```
445488

446-
Most production apps will require some level of customization to authorize user requests. We provide a sample Dockerfile in the xmtpd [`dev/docker`](https://github.com/xmtp/xmtpd/blob/main/dev/docker/gateway.Dockerfile) directory that you can use as a starting point.
489+
Most production apps will require some level of customization to authorize user requests. You can fork our [example repository](https://github.com/xmtp/gateway-service-example), which includes a Dockerfile and a sample configuration.
447490

448491
The system is able to run without any external dependencies, but we recommend configuring a Redis instance to use for nonce management and rate limiting.
449492

0 commit comments

Comments
 (0)