Cannot connect web3 php to ropsten test network

Hi, im a bit confused to connect my web3 php (laravel) with ropsten.
I successfully connect ganache blockchain to web3 php, this is some source code in laravel controller

 public function DecetralizeID(){
 $contractABI = //[{*some abi*}]

$contract = new Contract('http://127.0.0.1:7545/', $contractABI);
$contractAddress = "0xc17E4f191Fb9000262698eE4cDDE8bF66bFb6AA3";
$fromAccount = "0x9cdc1E3F896dD416660b7359A0bC81EAE5e1b93a"; //accounts[0] -

//SHOWLOGSBYOWNER
$contract->at($contractAddress)->call("showLogsByOwner", $fromAccount, function($err,$data) {
  if ($err !== null) {
    echo 'Error: ' . $err->getMessage();
    return;
  }
  echo 'showLogsByOwner : show id logs by address user :<br>';
  foreach ($data as $dt) {
      foreach($dt as $t) {
        echo $t;
        echo "<br>";
      }
  }

});
}

This worked perfectly, I can echo the function showLogsByOwner within the blockchain. The problem is how to connect it with ropsten test net.
i did this but failed, I change this line ::

$contract = new Contract('http://127.0.0.1:7545/', $contractABI);

to this

$contract = new Contract('https://ropsten.infura.io/v3/a3491ed6ac7a4c3a87a914bbe5a1xxxx/', $contractABI);

Then i run laravel again and I got error :
cURL error 28: Operation timed out after 1000 milliseconds with 0 out of 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://ropsten.infura.io/v3/a3491ed6ac7a4c3a87a914b

is there something I missing or what? please need your help

I also posted this issue on stackoverflow

hi @alvin , can you try a simple curl from the same machine and see if that works:

curl https://ropsten.infura.io/v3/a3491ed6ac7a4c3a87a914bbe5a1xxxx
-X POST
-H ā€œContent-Type: application/jsonā€
-d ā€˜{ā€œjsonrpcā€:ā€œ2.0ā€,ā€œmethodā€:ā€œeth_blockNumberā€,ā€œparamsā€: [],ā€œidā€:1}ā€™

hi @traian.vila , I try the curl, the result is I got error curl invalid json request(windows powershell) but in linux and postman, i got succesfull result

but thats not the main problem. the main problem is I can connect to ropsten with web3php, do you have some tutorials for this case ?

Yes, I was trying to exclude a connection issue, it sounds like a timeout problem. Try increasing the 1s default timeout and see how it goes:

:grinning:thanks sir, you save my life

1 Like