Position: Home page » Ethereum » PHP Ethereum RPC call interface

PHP Ethereum RPC call interface

Publish: 2021-05-02 04:24:39
1. How to run Ethereum source code go Ethereum
install MIPS based Linux header file
$CD $prjroot / kernel
$tar - xjvf linux-2.6.38. Tar. Bz2
$CD linux-2.6.38

create an include folder under the specified path to store related header files< br />$ mkdir -p $TARGET_ Prefix / include

ensures that the Linux source code is clean
$make mrproper

generates the required header file< br />$ make ARCH=mips headers_ check
$ make ARCH=mips INSTALL_ HDR_ PATH=dest headers_ Install

all the files in dest folder to the specified include folder< br />$ cp -rv dest/include/* $TARGET_ Prefix / include

delete dest folder at last
$RM - RF dest
$LS - L $target_ PREFIX/include
2. curl方法,file_get_contents,
3.

If you want to query the transaction records on the main network, you can use Etherscan. However, if you build your own private chain, how should you query the transaction records

the answer is that you need to listen to the logs on the chain, save them in the database, and then query them in the database. For example:

< pre t = "code" L = "Java" > varaddr = & quot& quot;< br />varfilter=web3.eth.filter({fromB lock:0 ,toBlock:' latest', address:addr });< br />filter.get(function(err,transactions){
transactions.forEach(function(tx){
vartxInfo=web3.eth.getTransaction(tx.transactionHash);
/ / at this time, the transaction information txinfo can be stored in the database
})< br />});

Web3. Eth. Filter() is used to monitor the log on the chain, and Web3. Eth. Gettransaction() is used to extract the information of the specified transaction. Once the transaction information is obtained, it can be stored in the database for query

recommend a practical introction, you can see: Ethereum tutorial

4. Through curl to simulate, and then get the data, and use it in JSON format
5.

Ethereum specifies the JSON RPC API application development interface that each node needs to implement. This interface is transport independent. Applications can use this interface protocol to operate Ethereum nodes through HTTP, websocket or IPC and other communication mechanisms:

6. 服务端示例:
<?php
namespace Rpc\Controller;
use Think\Controller\JsonRpcController;
class JsonApiController extends JsonRpcController
{
public function index(){
return 'Hello, JsonRPC!';
}
// 支持参数传入
public function test($name=''){
return "Hello, {$name}!";
}
}
客户端示例:
vendor('jsonRPC.jsonRPCClient');
$client = new \jsonRPCClient('http://www.tp.cn/index.php/Rpc/JsonApi');
$result = $client->index();
var_mp($result); // 结果:Hello, JsonRPC!
$result = $client->test('deeka');
var_mp($result); // 结果:Hello, deeka!
7. PHP integrates the access of XML-RPC and soap, both of which are focused on the extension of XMLRPC. In addition, in the pear of PHP, both PHP 4 and PHP 5 have integrated the XML-RPC extension by default, and this extension is independent of the XMLRPC extension, and can independently implement the protocol interaction of XML-RPC. If there is no XMLRPC extension, pear:: XML-RPC extension is recommended
Introction to web service
Web service is proced for the communication of heterogeneous systems. Its basic idea is to provide a standard mechanism by using HTTP remote call based on XML without the need to establish a new protocol. At present, there are two protocol standards for web service communication, one is XML-RPC, the other is soap. XML-RPC is relatively simple, appeared earlier, soap is relatively complex, mainly used when it needs stable, robust, safe and complex interaction
here, we mainly use XML-RPC to briefly describe the interaction process of web service. Part of the content is from the PHP manual. For more details, please refer to the manual
install the XMLRPC extension
if you don't have the PHP extension of XMLRPC installed on your system, please install it correctly
on the windows platform, first of all, expand PHP in the PHP installation directory_ Xmlrpc.dll to C: \ Windows or C: &? 92; In WinNT directory, (the extension of PHP4 is in C: & # 92; php\ In the extensions directory, the extension of PHP5 is in C: & # 92; php\ At the same time, in C: & # 92; Windows\ Php.ini or C: \ Winnt\ Extension = PHP in php.ini_ Semicolon before xmlrpc.dll & quot& quot; Remove it, and then restart the web server to see if phpinfo () has an XML-RPC project to determine whether the XML RPC extension has been properly installed
on UNIX / Linux platform, if the XMLRPC extension is not installed, please recompile PHP, add -- with XMLRPC option when configuring, and then check phpinfo() to see if the XMLRPC extension is installed normally
(Note: the following operations are based on the premise of normal installation of XMLRPC expansion, please be sure to install it correctly.)
working principle of XML-RPC
XML-RPC is basically the whole process of using XML to communicate. First of all, an RPC server is constructed to send the XML encapsulated request from the RPC client, and the processing result is returned to the RPC client in the form of XML. Then the client analyzes the XML to get the data it needs
the server side of XML-RPC must have ready-made functions to be called by the client side, and the functions and methods in the requests submitted by the client side must be consistent with those of the server side, otherwise the required results will not be obtained
I will describe the whole process with simple code
practice of XML-RPC
using XMLRPC in server_ server_ The create function generates a server, registers the RPC calling interface that needs to be exposed, accepts the XML data from the RPC client post, and processes it. The processing results are displayed to the client in the form of XML
the code is as follows: RPC_ server.php
<? PHP
/ *
* functions: functions provided to RPC clients to call
* parameters:
* $method functions to be called by clients
* $parameters array of functions to be called by clients
* Return: Returns the specified call result
* /
function RPC_ server_ func($method, $params) {
$parameter = $params[0];< br /> if ($parameter == " get"){< br /> $return = '&# 39; This data by get method'&# 39;;< br /> }else{
$return = '&# 39; Not specify method or params'&# 39;;< br /> }
return $return;
}
/ / generate an XML-RPC server-side
$XMLRPC_ server = xmlrpc_ server_ create();
/ / register a method RPC called by the server_ Server, which actually points to RPC_ server_ Func function
XMLRPC_ server_ register_ method($xmlrpc_ server, " rpc_ server", & quot; rpc_ server_ func");
/ / accept XML data from client post
$request = $http_ RAW_ POST_ DATA;
/ / after executing the XML request calling the client, get the execution result
$XMLRPC_ response = xmlrpc_ server_ call_ method($xmlrpc_ server, $request, null);
/ / output the result XML processed by the function
header (& # 39&# 39; Content-Type: text/xml'&# 39;);< br />echo $xmlrpc_ response;
/ / destroy XML-RPC server-side resources
XMLRPC_ server_ destroy($xmlrpc_ server);< br />?& gt;
after the server is constructed, we can construct our RPC client. The client accesses port 80 of the XML-RPC server through socket, encapsulates the RPC interface to be called into XML, submits the request to the RPC server through post, and finally obtains the result returned by the server
the code is as follows: RPC_ client.php
<? PHP
/ *
* functions: functions provided to clients to connect to XML-RPC servers
* parameters:
* $host host to connect to
* $port to connect to host port
* $RPC_ Server XML-RPC server-side file
* $request encapsulated XML request information
* Return: successful connection returns the XML information returned by the server, and failure returns false
* /
function RPC_ client_ call($host, $port, $rpc_ Server, $request) {
/ / open the specified server side
$FP = fsockopen ($host, $port)
/ / construct the query post request information of the XML-RPC server that needs to communicate
$query = & quot; POST $rpc_ server HTTP/1.0\ nUser_ Agent: XML-RPC Client\ nHost: ".$ host."&# 92; nContent-Type: text/xml\ nContent-Length: ". strlen($request)."&# 92; n\ n".$ request."&# 92; n";
/ / send the constructed HTTP protocol to the server. If it fails, return false
if (! fputs($fp, $query, strlen($query))) {
$errstr = " Write error";< br /> return false;<
}

/ / get all the information returned from the server, including HTTP header and XML information
$contents = & 39&# 39;&# 39;&# 39;;< br /> while (! feof($fp)){
$contents .= fgets($fp);
}
/ / after closing the connection resource, the obtained content is returned
Fclose ($FP)< br /> return $contents;
}
/ / construct the connection information of RPC server side
$host = & 39&# 39; localhost'&# 39;;< br />$port = 80;< br />$rpc_ server = '&# 39;/~ heiyeluren/rpc_ server.php'&# 39;;
/ / to encode the XML request to be sent into XML, the method to be called is RPC_ Server, the parameter is get
$request = XMLRPC_ encode_ request('&# 39; rpc_ server'&# 39;, &# 39;&# 39; get'&# 39;);
/ / call RPC_ client_ The call function sends all the requests to the XML-RPC server and gets the information
$response = RPC_ client_ call($host, $port, $rpc_ server, $request);
/ / analyze the XML returned from the server, remove the HTTP header information, and convert the XML to a string that PHP can recognize
$split = & 39&# 39;& lt;? xml version=" 1.0" encoding=" iso-8859-1"?& gt;&# 39;&# 39;;< br />$xml = explode($split, $response);< br />$xml = $split . array_ pop($xml);< br />$response = xmlrpc_ decode($xml);
/ / output the information obtained from RPC server
Print_ r($response);< br />?& gt;
in general, the above example is to submit an RPC_ In the past, the parameter of the server method was get, and then get the return of the server. The XML data returned by the server is:
& lt;? xml version=" 1.0" encoding=" iso-8859-1"?& gt;< br />< methodResponse>< br />< params>< br />< param>< br /> < value>< br /> < string> This data by get method</ string>< br /> </ value>< br /></ param>< br /></ params>< br /></ methodResponse>
then we can use XMLRPC_ The decode function encodes this XML into a PHP string, so we can handle it at will, and the whole web service interaction is completed.
8. Let's talk about an idea. Let's see if we adopt it or not:
communicate with socket:
with the existing protocol, you can rely on HTTP to realize the local access interface, that is, 127.0.0.1 + HTTP port
or
define data transmission rules by themselves, relying on the pure socket interface of Java
or
Web service needs data encapsulation, which is not as efficient as HTTP direct call
the implementation of the above methods is not big. Php100% has network request or WebService function, so you don't need to worry about the efficiency. 127.0.0.1 communication, data can't even be transferred to the network card, and it is directly transferred to other processes and deployed on different machines. Data needs to go through the network
another way:
remote procere call, whether it can communicate across languages quickly or not, I don't want to, but RPC is an instry standard, if we strictly follow the standard, it can be realized in theory. PHP has no corresponding call function, it is not clear
I am familiar with Java and PHP
all the above methods are common interfaces after you write them. You can deploy them on any platform you want.
9. A. The mass number of C, D, < sub > Z < / sub > < sup > a < / sup > x is a, the proton number is Z < br > the mass number = the proton number + the neutron number, so the neutron number is A-Z, so a is correct, CD is wrong. < br > b, if the nucleon number = the proton number + the neutron number, then the nucleon number is equal to the mass number, which is a. so B is correct. < br > so select ab
Hot content
Inn digger Publish: 2021-05-29 20:04:36 Views: 341
Purchase of virtual currency in trust contract dispute Publish: 2021-05-29 20:04:33 Views: 942
Blockchain trust machine Publish: 2021-05-29 20:04:26 Views: 720
Brief introduction of ant mine Publish: 2021-05-29 20:04:25 Views: 848
Will digital currency open in November Publish: 2021-05-29 19:56:16 Views: 861
Global digital currency asset exchange Publish: 2021-05-29 19:54:29 Views: 603
Mining chip machine S11 Publish: 2021-05-29 19:54:26 Views: 945
Ethereum algorithm Sha3 Publish: 2021-05-29 19:52:40 Views: 643
Talking about blockchain is not reliable Publish: 2021-05-29 19:52:26 Views: 754
Mining machine node query Publish: 2021-05-29 19:36:37 Views: 750