You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法在CodeIgniter中使用Composer引入的geth-jsonrpc-php-client库

Fixing "Class 'GuzzleClient' not found" when using geth-jsonrpc-php-client in CodeIgniter

Hey there, let's break down why you're hitting this error and fix it step by step:

What's Causing the Issue?

You've got three key problems here:

  1. Missing Namespace Imports: The GuzzleClient and Client classes from the geth library live under specific namespaces—PHP can't find them if you don't tell it where to look.
  2. Composer Autoload Not Enabled: CodeIgniter doesn't automatically load Composer-installed dependencies unless you flip a config switch.
  3. Invalid Constructor Return: PHP constructors (__construct()) aren't supposed to return values—this is a syntax misstep that'll cause unexpected behavior even if the class issue is fixed.

Step-by-Step Fixes

1. Turn On Composer Autoload in CodeIgniter

First, head to application/config/config.php and find the composer_autoload setting. Set it to TRUE to let CodeIgniter use Composer's autoloader:

$config['composer_autoload'] = TRUE;

If your vendor folder isn't in the default root path, point directly to the autoload file instead:

$config['composer_autoload'] = FCPATH . 'vendor/autoload.php';

2. Fix Your Custom Ethereum Library Code

We need to add the namespace imports, fix the constructor, and store the client as a class property so you can use it later:

<?php
// Import the required classes from the library's namespace
use Achse\GethJsonRpcPhpClient\HttpClient\GuzzleClient;
use Achse\GethJsonRpcPhpClient\HttpClient\GuzzleClientFactory;
use Achse\GethJsonRpcPhpClient\Client;

class Ethereum {
    // Store the client instance as a private class property
    private $client;

    public function __construct() {
        $clientFactory = new GuzzleClientFactory();
        $httpClient = new GuzzleClient($clientFactory, 'localhost', 8545);
        $this->client = new Client($httpClient);
    }

    // Add a method to retrieve the client instance when you need it
    public function getClient() {
        return $this->client;
    }
}

3. Verify Your Composer Dependencies

Double-check that you've actually installed the library via Composer. Run this in your project root if you haven't already:

composer require achse/geth-jsonrpc-php-client

If it's already installed, run composer dump-autoload to refresh the autoloader mapping—this ensures PHP can find all the new classes.


Quick Extra Tips

  • Make sure your Geth node is actually running on localhost:8545—if it's on a different host/port, update those values in the GuzzleClient constructor.
  • When using this library in CodeIgniter, load it with $this->load->library('ethereum');, then access the client with $this->ethereum->getClient(); to interact with your Geth node.

内容的提问来源于stack exchange,提问作者Haren Sarma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:50:58