Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Eth Rpc Client Php Laravel Package

amashukov/eth-rpc-client-php

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • EVM/Blockchain Integration: Ideal for PHP-based Ethereum/EVM applications requiring direct JSON-RPC interaction (e.g., wallets, DeFi tools, oracles, or smart contract monitoring). The dual-layer design (EthRpcClient for raw parity, JsonRpcProvider for typed abstractions) aligns well with modern PHP architectures needing both audit-grade precision and developer-friendly APIs.
  • PSR Standards Compliance: Leverages PSR-18 (HTTP client), PSR-17 (HTTP factories), and PSR-20 (clock) for loose coupling, enabling seamless integration with existing PHP ecosystems (e.g., Symfony, Laravel, or custom stacks).
  • EIP-1559 Support: Critical for modern Ethereum applications, ensuring compatibility with London-era fee markets. The package’s fee math (maxFeePerGas = 2 × baseFee + tip) mirrors ethers.js v6, reducing friction for developers familiar with JavaScript tooling.

Integration Feasibility

  • Low-Coupling Design: Transport-agnostic architecture allows swapping HTTP clients (e.g., Guzzle, Symfony HTTP Client) without modifying core logic. Middleware (e.g., retries, auth) can be injected via PSR-18 pipelines.
  • Type Safety: Typed Value Objects (EthereumTransaction, EthereumFeeData) reduce runtime errors and improve IDE support (e.g., PHPStan, PhpStorm). Decimal-string handling for large wei values avoids floating-point precision issues.
  • Node Quirk Tolerance: Gracefully handles edge cases (e.g., Erigon’s 0x returns, pre-London blocks), reducing operational overhead for multi-node setups.

Technical Risk

  • Maturity: Low stars/dependents and minimal documentation suggest unproven adoption. Risk mitigated by:
    • PHPStan L9: High code quality reduces hidden bugs.
    • Ethers.js Parity: Fee math and VO design validated against a battle-tested JS library.
    • MIT License: Permissive terms enable safe experimentation.
  • PHP 8.3+ Dependency: May require upgrades for legacy systems, but aligns with modern PHP LTS.
  • GMP/BCMath: Extensions are standard on most Linux servers but may need enabling on shared hosting.
  • Testing Gaps: Lack of dependents implies untested edge cases (e.g., custom RPC endpoints, non-standard responses). Recommendation: Load-test with diverse node providers (Alchemy, Infura, local Geth/Nethermind).

Key Questions

  1. Use Case Alignment:
    • Is the project building a high-frequency system (e.g., MEV bots) where raw EthRpcClient parity is critical, or is JsonRpcProvider’s abstraction sufficient?
    • Does the team need offline signing? If so, pair with amashukov/eip1559-tx-signer-php.
  2. HTTP Client Strategy:
    • Will the team use the bundled CurlClient or integrate an existing PSR-18 client (e.g., Guzzle)? Middleware (retries, auth) must be planned upfront.
  3. Scaling Assumptions:
    • The package assumes synchronous RPC calls. For high-throughput apps, consider async PSR-18 clients (e.g., ReactPHP) or batching.
  4. Monitoring:
    • How will RPC latency/errors be monitored? The package lacks built-in telemetry; integrate with tools like Prometheus or Sentry.
  5. Fork Compatibility:
    • Test with non-Ethereum EVM chains (e.g., Polygon, Arbitrum) to validate eth_* method compatibility.

Integration Approach

Stack Fit

  • PHP Ecosystem: Perfect for Laravel/Symfony apps needing blockchain interop. Example:
    • Laravel: Use HttpClient facade (PSR-18) + JsonRpcProvider in services.
    • Symfony: Inject CurlClient with middleware (e.g., RetryMiddleware) via DIC.
  • Microservices: Ideal for blockchain listeners (e.g., new block/transaction webhooks) or oracles fetching on-chain data.
  • CLI Tools: Lightweight for scripts (e.g., gas fee monitoring, contract verification).

Migration Path

  1. Pilot Phase:
    • Replace web3.php (if used) with EthRpcClient for audit paths, JsonRpcProvider for new code.
    • Example: Migrate a single service (e.g., gas estimation) to validate performance.
  2. Incremental Adoption:
    • Step 1: Integrate JsonRpcProvider for typed queries (e.g., getBalance, getFeeData).
    • Step 2: Adopt EthRpcClient for hex-parity needs (e.g., debugging).
    • Step 3: Replace custom RPC logic with the package’s methods.
  3. Middleware Layering:
    • Wrap the PSR-18 client with retries/auth (e.g., using amashukov/http-client-php):
      $http = new Pipeline([
          new RetryMiddleware(),
          new AuthMiddleware('Bearer ' . $apiKey),
          new CurlClient($psr17, $psr17),
      ]);
      $client = new EthRpcClient($http, $psr17, $psr17, $rpcUrl);
      

Compatibility

  • PSR-18 Clients: Works with any compliant client (e.g., Guzzle 6/7, Symfony HTTP Client, ReactPHP).
  • RPC Endpoints: Supports standard Ethereum JSON-RPC (e.g., Infura, Alchemy, local nodes). Test with:
    • Public Testnets: Sepolia, Goerli (for EIP-1559 validation).
    • Private Nodes: Ensure custom RPC methods (e.g., debug_traceCall) are not relied upon.
  • Legacy Systems: Avoid if using PHP <8.3 or lacking GMP/BCMath.

Sequencing

  1. Dependency Setup:
    • Install via Composer:
      composer require amashukov/eth-rpc-client-php amashukov/http-client-php
      
    • Enable ext-gmp and ext-bcmath in php.ini.
  2. Configuration:
    • Centralize RPC URLs and HTTP clients in config (e.g., Laravel’s .env or Symfony’s parameters.yml).
  3. Testing:
    • Mock Psr\Clock\ClockInterface for waitForTransaction deadlines.
    • Test fee calculations against ethers.js or Hardhat for parity.
  4. Deployment:
    • Start with read-only methods (e.g., eth_getBalance), then enable writes (e.g., eth_sendRawTransaction).

Operational Impact

Maintenance

  • Pros:
    • MIT License: No vendor lock-in.
    • PSR Standards: Easy to maintain/update dependencies.
    • Type Safety: Reduces runtime errors in production.
  • Cons:
    • Single Maintainer: Low-star repo implies potential abandonment. Mitigate by:
      • Forking for critical fixes.
      • Contributing upstream (e.g., docs, tests).
    • Documentation Gaps: Limited examples; build internal runbooks for:
      • Common RPC methods (e.g., eth_call, eth_getLogs).
      • Error handling (e.g., rate limits, node timeouts).

Support

  • Debugging:
    • Use EthRpcClient for raw hex inspection when JsonRpcProvider returns unexpected data.
    • Log raw RPC responses for node-specific quirks (e.g., Erigon’s 0x returns).
  • Community:
    • Limited to GitHub issues/PRs. Plan for:
      • Internal Slack/Discord channels for team knowledge sharing.
      • Fallback to ethers.js docs for API reference.
  • Vendor Support:
    • No SLA for upstream fixes. Prioritize:
      • Feature requests (e.g., EIP-4844 support).
      • Bug reports with reproduction steps.

Scaling

  • Performance:
    • Synchronous by Default: Not ideal for high-frequency apps (e.g., MEV). Solutions:
      • Use async PSR-18 clients (e.g., ReactPHP) for parallel requests.
      • Implement request batching (e.g., eth_call for multiple addresses).
    • Rate Limiting: RPC providers (e.g., Infura) throttle requests. Add:
      • Exponential backoff middleware.
      • Circuit breakers for failed nodes.
  • Resource Usage:
    • GMP/BCMath operations are CPU-intensive for large wei values. Benchmark:
      • getBalance for contracts with high token supplies.
      • eth_call with complex state changes.
  • Horizontal Scaling:
    • Stateless design allows scaling RPC clients behind a load balancer (e.g., Kubernetes).

Failure Modes

Failure Scenario Impact Mitigation
RPC Node Unavailable App downtime Multi
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity