In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you the "EOS blockchain PHP development kit how to use", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "EOS blockchain PHP development kit how to use" this article.
1. Overview of the development package
The purpose of EosTool is to eliminate the pain of using PHP to develop EOS blockchain applications, such as:
Call its function through the RPC interface of Nodeos and Keosd
Offline generation of private and public keys in EOS format
Use the local private key to generate a transaction signature that meets the EOS requirements
Serialize the transaction object into the packed_trx format required by Nodeos
It can be considered that EosTool is the PHP version of eosjs, which can not only fully realize the function of EOS official client Cleos, but also easily increase the ability to support EOS block chain in PHP applications, and greatly improve the development efficiency.
Interested friends can also visit here directly, and the content of this article is transferred from the blog: EOS Block chain PHP Development Kit
EosTool runs under the environment of * * Php 7.1 drivers *. The current version 1.0.0. The main code files are as follows:
The code file indicates that eostool/src/client/NodeClient.php node software nodeos's rpc interface encapsulation class eostool/src/client/WalletClient.php wallet software keosd's rpc interface wrapper class eostool/src/client/RpcOutput.phpRPC returns the result wrapper class eostool/src/Crypto/PrivateKey.phpEOS private key class eostool/src/Crypto/PublicKey.phpEOS public key class eostool/src/Crypto/Signature.phpEOS signature class ABI type wrapper class eostool/src/ Serializer/AbiTypeFactory.phpABI type factory class eostool/src/Serializer/SerialBuffer.php serialization buffer implementation class eostool/src/Serializer/Serializer.php serializer implementation class eostool/src/Signer/Signer.php signer interface eostool/src/Signer/KeosdSigner.phpKeosd signer implementation class eostool/src/Signer/LocalSigner.php local offline signer implementation interface eostool/src/Contract.php contract class eostool/src/EosTool.php development package entry class eostool/tests single Meta test case directory eostool/phpunit.xml unit test configuration file eostool/vendor third-party dependency package eostool/composer.jsoncomposer configuration file 2. Access node server
Use the NodeClient class to access the rpc interface of nodeos. For example, the following code accesses the get_info interface of the chain plug-in of the native running Nodeos node:
Use EosTool\ Client\ NodeClient;$nc = new NodeClient (); $ret = $nc- > chain- > getInfo (); if ($ret- > hasError ()) throw new Exception ($ret- > getError ()); $info = $ret- > getResult ()
2.1 RPC call grouping
Nodeos adopts plug-in architecture, the API of different plug-ins are also grouped into different groups, EosTool adopts a consistent naming method, and the calling method of NodeClient can be inferred from api: API grouping corresponds to an attribute of the same name of NodeClient, and API corresponds to a method transformed by camelCase under the same name attribute of No's Client. For example:
Plug-in API grouping RPC APINodeClient method chain_api_pluginchainget_info$nc- > chain- > getInfo () history_api_pluginhistoryget_transaction$nc- > history- > getTransaction () net_api_pluginnetstatus$nc- > net- > status () producer_api_pluginproducerget_runtime_options$nc- > producer- > getRunTimeOptions () dbsize_api_plugindbsizeget$nc- > dbsize- > get ()
Official document of RPC API: https://developers.eos.io/eosio-nodeos/reference
2.2 RPC call parameters
For Nodeos, some calls require passing additional parameters, such as the get_block API of the chain plug-in. When calling with EosTool, you can organize the parameters into an associative array. The sample code is as follows:
$payload = ['block_num_or_id' = > 1]; $ret = $nc- > chain- > getBlock ($payload)
2.3 return value from RPC call
The return result of all RPC calls is a RpcOutput instance, and calling its hasError () method can determine whether there is an error in the call, and further, you can use the getError () method to get the error information.
The response to the RPC call can be obtained through the getResult () method, which is a StdClass object converted from the original JSON result, so you can easily extract attribute information, such as:
Echo 'chain id'. $info- > chain_id. PHP_EOL
2.4 access to the main / test network node
When creating a NodeClient instance, you can pass in additional parameters for execution to determine which EOS major network or test network node to access. For example, use the following code to access a major network node:
$nc = new NodeClient (['base_uri' = >' https://api.eosnewyork.io:443/v1/']);
Or visit a node of the jungle test network:
$nc = new NodeClient (['base_uri' = >' https://jungle.eosio.cr:443/v1/']);3, access the wallet server
The new version of Keosd no longer provides RPC API documentation, which may mean that it has begun to slide to the edge of the EOS software stack. However, you can access the old document: https://developers.eos.io/eosio-nodeos/v1.1.0/reference at this address.
Use the WalletClient class to access the rpc interface of Keosd. For example, the following code accesses the list_wallets interface of the native running Keosd:
Use EosTool\ Client\ WalletClient;$wc = new WalletClient (); $ret = $wc- > listWallets (); if ($ret- > hasError ()) throw new Exception ($ret- > getError ()); $wallets = $ret- > getResult ()
Because the API of Keosd is no longer grouped, the corresponding method of RPC is hung directly on the WalletClient object, which is a difference. Like NodeClient, the call to WalletClient returns a RpcOutput object.
Version 1.4 of Keosd defaults to using UNIX sockets instead of HTTP to provide a RPC interface, which is probably due to the fact that in most cases Keosd runs natively, and it is safer to use IPC. So this is also the default instantiation option for WalletClient, and in most cases you don't need to pass in additional parameters to instantiate WalletClient.
4. Private key and public key
EOS's key algorithm is similar to Bitcoin, but with some adjustments to define its own format.
Use the static method new () of the PrivateKey class to generate a random private key. For example:
Use EosTool\ Crypto\ PrivateKey;$prv = PrivateKey::new (); echo $prv- > toEos (). PHP_EOL; / / similar: 5Hu6nxM6s6UQ3nYkr1s1GKA17zPqpceUuWxH3JBwK8ZorMSRqGi
The toEos () method is used to convert the private key object to the custom format of EOS.
4.1 Public key derivation
A public key can be derived from a private key, for example:
$pub = $prv- > getPublicKey (); echo $pub- > toEos (). PHP_EOL; / / similar: EOS6wQ6t3n148GfzLzgxq7cC8ARDKxeaB3hQXdXn7oZYdwEyAXiSv
Similarly, use the toEos () method to convert the public key to the custom format of EOS.
4.2 Import EOS private key
You can convert a private key in EOS format to a PrivateKey object of EosTool. For example, the following code imports the specified EOS private key and displays its corresponding EOS public key:
$prv = PrivateKey::fromEos ('5Hu6nxM6s6UQ3nYkr1s1GKA17zPqpceUuWxH3JBwK8ZorMSRqGi'); echo $prv- > getPublicKey ()-> toEos (). PHP_EOL
4.3 authoritative signature
The sign () method of PrivateKey supports both normal signatures and authoritative signatures required by the EOS node. For example, the following code returns a normal signature:
$hex = '1234567890abcdef.alternative signature = $prv- > sign ($hex)
Pass in additional parameters to obtain the authoritative signature of the specified data:
$hex = '1234567890abcdef.alternative signature = $prv- > sign ($hex,true); 5. Serialization
EOS requires transactions to be serialized before submitting the node push_transaction, which is also a part of the EOS transaction that cannot be bypassed in PHP.
In EosTool, you use the Serializer class for serialization operations. For example, the following code serializes an EOS transfer transaction into a hexadecimal stream format that can be submitted to the EOS node:
Use EosTool\ Serializer\ Serializer;$abi = json_decode (file_get_contents ('transaction.abi'), true); $serializer = Serializer::fromAbi ($abi) $tx = ['expiration'= >' 2018-12-04T17VIED 00V, 'ref_block_num' = > 2878,' ref_block_prefix' = > 29012031, 'max_net_usage_words' = > 0,' max_cpu_usage_ms' = > 0, 'delay_sec' = > 0,' context_free_actions' = > [], 'actions' = > [' account' = > 'eosio.token',' name' = > 'transfer'' 'authorization' = > [[' actor' = > 'eosio',' permission' = > 'active']],' data' = > '11223344556677889900112233456677.889900']],' transaction_extensions' = > [] $hex = $serializer- > serialize ('transaction',$tx); echo' serialized tx = >'. $hex. PHP_EOL
Serializer's static method fromAbi () is used to construct a serializer instance based on a specified abi, and then serialize the specified type of data using the instance's serialize () method to get a hexadecimal stream.
6. Signature
EosTool provides two ways to sign a transaction: sign with Keosd or sign with a local private key.
Use the KeosdSigner class to complete the signature using the wallet server. For example:
Use EosTool\ Signer\ KeosdSigner;$signer = new KeosdSigner (); $signatures = $signer- > sign ($tx,$pubKeys,$chainId)
With the LocalSigner class, you can avoid using keosd and sign with the offline private key directly. For example:
Use EosTool\ Signer\ LocalSigner;$prvKeys = ['5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3']; $signer = new LocalSigner ($prvKeys); $signatures = $signer- > sign ($tx,$pubKeys,$chainId); 7. Deal submission
A transaction data needs to be normalized, serialized, signed and packaged before it can be submitted to the Nodeos node for broadcast. The EosTool class provides a transact () method to isolate these tedious operations.
For example, the following code creates an instance of EosTool using NodeClient and LocalSigner, and then submits a transaction:
Use EosTool\ Client\ NodeClient;use EosTool\ Signer\ LocalSigner;use EosTool\ EosTool;$nc = new NodeClient (); $signer = new LocalSigner (['5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3']); $tool = new EosTool ($nc,$signer) $tx = ['actions' = > [[' account' = > 'eosio.token',' name' = > 'transfer',' authorization' = > [['actor' = >' eosio', 'permission' = >' active']], 'data' = > [' from' = > 'eosio',' to' = > 'tommy',' quantity' = > '200.0000 EOS',' memo' = > 'take care'] $ret = $tool- > transact ($tx); echo $ret- > getResult ()-> transaction_id. PHP_EOL
You can easily change the signer to KeosdSigner, for example:
$nc = new NodeClient (); $signer = new KeosdSigner (); $tool = new EosTool ($nc,$signer); 8. Invoke a single contract action
Use the pushAction () method of EosTool to invoke a single contract action. For example, the following code calls the hi () method of the tommy account hosting contract:
$tool = new EosTool (new NodeClient (), new KeosdSigner ()); $ret = $tool- > pushAction ('tommy','hi', [' user'= > 'tommy']); 9. Deployment contract
Deploy the contract using the setContract () method of EosTool, for example:
$tool = new EosTool (new NodeClient (), new KeosdSigner ()); $account = 'tommy';$abi = file_get_contents (' hello.abi'); $wasm = file_get_contents ('hello.wasm'); $ret = $tool- > setContract ($account,$abi,$wasm); these are all the contents of the article "how to use the EOS blockchain PHP Development Kit". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 217
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Ffmpeg-hwaccel nvdec-I test.h364 output_yuvffplay-video_size 2048x1536-I output.yuv
© 2024 shulou.com SLNews company. All rights reserved.