将web3-php连接到ropsten测试网络



我成功地将ganache区块链连接到了web3-php,这是laravel控制器中的一些源代码:

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>";
}
}
});
}

这非常完美,我可以在区块链中呼应showLogsByOwner的功能。问题是如何将它与ropsten测试网连接起来
我这样做了,但失败了,我更改了这一行:

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

类似的东西:

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

然后我再次运行laravel,我得到了一个错误:

cURL错误28:操作在1000毫秒后超时,收到0个字节中的0个(请参阅https://curl.haxx.se/libcurl/c/libcurl-errors.html)forhttps://ropsten.infura.io/v3/a3491ed6ac7a4c3a87a914b

我缺少什么吗?

我从元任务扩展得到了ropsten id->设置->网络(Ropsten Test Net RPC URL(

经过对这个repos:的一些研究

  • https://github.com/web3p/web3.php
  • https://github.com/web3p/ethereum-tx

我可以通过将实例$contract编辑为:来解决此问题

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

感谢@JoséCarlos PHP的评论

最新更新