alvin Christianto
alvin Christianto

Reputation: 106

Connect web3 php to ropsten test network

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 something like this :

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

Then I run laravel again and I got an 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'm missing?

I get ropsten id from metamask extention -> settings -> Networks (Ropsten Test Net RPC URL)

Upvotes: 0

Views: 983

Answers (1)

alvin Christianto
alvin Christianto

Reputation: 106

after some research on this repos :

I can solve this case by edit instance $contract to :

$timeout = 10;
$contract = new Contract(new HttpProvider(new HttpRequestManager("https://ropsten.infura.io/v3/a3491ed6ac7a4c3a87a914bbe5a1xxxx", $timeout)) , $contractABI);

thankyou @José Carlos PHP for the comment

Upvotes: 0

Related Questions