web3p / web3.php

A php interface for interacting with the Ethereum blockchain and ecosystem. Native ABI parsing and smart contract interactions.
MIT License
1.17k stars 555 forks source link

Error: Class "Web3\Web3" not found #361

Closed despicableGruu closed 1 month ago

despicableGruu commented 1 month ago

Here is my composer config file.

{
    "require": {
        "web3p/web3.php": "0.3.2"
    }
}

OS: Ubuntu 22.04 (WSL) PHP version: PHP 8.1.2-1ubuntu2.19 (cli) Composer version: 2.2.6

This is my index.php file.

<?php

use Web3\Web3;

$web3 = new Web3("https://rpc.ankr.com/eth");

I run this using php index.php and got error here.

PHP Fatal error:  Uncaught Error: Class "Web3\Web3" not found in /home/user/work/index.php:5
Stack trace:
#0 {main}
  thrown in /home/user/work/index.php on line 5

Please help me to fix this error.

NinjaCoder0516 commented 1 month ago

@despicableGruu Please add the following code snap before use Web3\Web3.

require_once "vendor/autoload.php";
despicableGruu commented 1 month ago

@despicableGruu Please add the following code snap before use Web3\Web3.

require_once "vendor/autoload.php";

It worked. Thanks.