0

I'm new to PHP, and I was trying to run $exampleBase.php from web3.php on mac
but it keeps showing error :

PHP Fatal error: Uncaught Error: Class 'Web3\Web3' not found in /Users/hsnl/Desktop/code/back-end-php/web3.php/examples/exampleBase.php:7 Stack trace: #0 {main} thrown in /Users/hsnl/Desktop/code/back-end-php/web3.php/examples/exampleBase.php on line 4

$exampleBase.php file is like this

<?php
require('vendor/autoload.php');
use Web3\Web3;
$web3 = new Web3('http://localhost:8545/');

any idea why or how should I fix this?

TylerH
  • 20,799
  • 66
  • 75
  • 101
李孟儒
  • 1
  • 1
  • Do you have `Web3\Web3` defined in your `composer.json` file? Did you run `composer install`? – Alex Howansky Sep 12 '18 at 18:04
  • i use the `$composer.json` file in web3.php on [github](https://github.com/sc0Vu/web3.php/blob/master/composer.json) but yet I dont see a specific definition of Web3\Web3. what should I add in the file? @AlexHowansky – 李孟儒 Sep 13 '18 at 04:28

1 Answers1

1

If you are trying to run sc0Vu, please try to follow this steps: https://github.com/sc0Vu/web3.php#local-php-cli-installed

Clone the repo and install packages.

git clone https://github.com/sc0Vu/web3.php.git && cd web3.php && composer install

This means:

  • clone github project,
  • go to cloned directory,
  • run composer install (will download and create all necessary files with classes)

Run test script.

vendor/bin/phpunit