博客
关于我
Php调用以太坊json rpc接口
阅读量:612 次
发布时间:2019-03-13

本文共 559 字,大约阅读时间需要 1 分钟。

以太坊规定了每个节点需要实现的JSON RPC应用开发接口,如果希望使用PHP开发一个以太坊区块链上的去中心化应用(DApp),首先要解决的问题就是如何使用PHP调用:

这里写图片描述

如果你希望将网站快速接入以太坊,例如支持以太币支付,或者发行自己的代币,那么这个

课程提供了最佳的学习路径。

虽然接口规范并没有对传输层进行约定,但大多数以太坊节点软件都实现了对HTTP协议的支持。

因此我们可以使用Php的HTTP开发包来进行调用。例如,下面的代码使用guzzle这个http开发包来获取以太坊节点旳版本信息:

[ 'jsonrpc' => '2.0', 'method' => 'web3_clientVersion', 'params' => [], 'id' => time() ]];$rsp = $client->post('http://localhost:8545',$opts);echo $rsp->getBody() . PHP_EOL;?>

当然你也可以借助于一些开源的封装,不过在php社区中,目前还缺乏得到统一认可的、相对比较成熟的以太坊开发包,因此在DApp的开发过程中,理解这些开源代码的实现原理就至关重要,而且往往需要综合利用多方面的代码资源才能解决问题。

原文:

你可能感兴趣的文章
nginx+mysql+redis+mongdb+rabbitmq 自动化部署脚本
查看>>
nginx+php的搭建
查看>>
Nginx+Redis+Ehcache:大型高并发与高可用的三层缓存架构总结
查看>>
nginx+tomcat+memcached
查看>>
nginx+tomcat单个域名及多个域名配置
查看>>
Nginx+Tomcat实现动静分离
查看>>
nginx+Tomcat性能监控
查看>>
nginx+uwsgi+django
查看>>
nginx+vsftp搭建图片服务器
查看>>
Nginx-http-flv-module流媒体服务器搭建+模拟推流+flv.js在前端html和Vue中播放HTTP-FLV视频流
查看>>
nginx-vts + prometheus 监控nginx
查看>>
Nginx/Apache反向代理
查看>>
Nginx: 413 – Request Entity Too Large Error and Solution
查看>>
nginx: [emerg] getpwnam(“www”) failed 错误处理方法
查看>>
nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:
查看>>
nginx: [error] open() “/usr/local/nginx/logs/nginx.pid“ failed (2: No such file or directory)
查看>>
nginx:Error ./configure: error: the HTTP rewrite module requires the PCRE library
查看>>
Nginx:objs/Makefile:432: recipe for target ‘objs/src/core/ngx_murmurhash.o‘解决方法
查看>>
nginxWebUI runCmd RCE漏洞复现
查看>>
nginx_rtmp
查看>>