【问题标题】:Connect web3 php to ropsten test network将 web3 php 连接到 ropsten 测试网络
【发布时间】: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


【解决方案1】:

在对这个 repos 进行一些研究之后:

我可以通过编辑实例 $contract 来解决这个问题:

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

感谢@José Carlos PHP 的评论

【讨论】:

    猜你喜欢
    • 2018-09-30
    • 2018-04-10
    • 1970-01-01
    • 2018-08-24
    • 1970-01-01
    • 2022-07-22
    • 1970-01-01
    • 1970-01-01
    • 2015-11-15
    相关资源
    最近更新 更多