【发布时间】:2021-12-17 16:56:23
【问题描述】:
我成功将 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 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
有什么我想念的或什么。请需要你的帮助
ps:
- 我从元掩码扩展中获取 ropsten id -> 设置 -> 网络(Ropsten 测试网络 RPC URL)
【问题讨论】:
-
乍一看,是连接问题(超时)。
-
我认为同样的@JoséCarlosPHP,我给了 30 秒睡眠,仍然收到警告。
标签: php laravel blockchain web3