This article is a mirror article of machine translation, please click here to jump to the original article.

View: 9838|Reply: 4

EOS Blockchain PHP Development Kit

[Copy link]
Posted on 12/11/2018 8:56:36 AM | | |
This post was last edited by jimi2018 on 2018-12-11 09:06

1. Development package overview
The purpose of EosTool is to eliminate the pain of developing EOS blockchain applications using PHP, such as:
  • Call its functions through the RPC interface of Nodeos and Keosd
  • Generate private and public keys in EOS format offline
  • Use your local private key to generate EOS-compliant transaction signatures
  • Serialize transaction objects into the packed_trx format required by Nodeos
It can be considered that EosTool is a PHP version of eosjs, which can be used to fully implement the functions of EOS official client Cleos, and it can also be easily added to the support of EOS blockchain in PHP applications, greatly improving development efficiency.

Interested friends can also go directly to this to download the EOS blockchain PHP development kit:http://t.cn/EUZAODQ

EosTool runs in Php 7.1+ environment, the current version is 1.0.0, and the list of main code files is as follows:

Code filesillustrate
eostool/src/client/NodeClient.phpThe RPC interface package class of node software nodeos
eostool/src/client/WalletClient.phpThe RPC interface encapsulation class of the wallet software KEOSD
eostool/src/client/RpcOutput.phpRPC returns the resulting encapsulation class
eostool/src/Crypto/PrivateKey.phpEOS private key class
eostool/src/Crypto/PublicKey.phpEOS public key class
eostool/src/Crypto/Signature.phpEOS signature class
eostool/src/Serializer/AbiType.phpEOS's ABI type package class
eostool/src/Serializer/AbiTypeFactory.phpABI type factory class
eostool/src/Serializer/SerialBuffer.phpSerialized buffer implementation class
eostool/src/Serializer/Serializer.phpserializer implementation class
eostool/src/Signer/Signer.phpSigner interface
eostool/src/Signer/KeosdSigner.phpKeosd signer implementation class
eostool/src/Signer/LocalSigner.phpLocal offline signer implementation
eostool/src/Contract.phpContract class
eostool/src/EosTool.phpDevelopment package entry class
eostool/testsUnit test case catalog
eostool/phpunit.xmlUnit test profiles
eostool/vendorThird-party dependency packages
eostool/composer.jsoncomposer configuration file
2. Access the node server
Use the NodeClient class to access nodeos' rpc interface. For example, the following code accesses the get_info interface of the chain plugin for a natively running Nodeos node:
2.1 RPC call grouping

EosTool adopts a consistent naming method, and the call method of NodeClient can be inferred according to the API: the API grouping corresponds to a property of the same name as the NodeClient, and the API corresponds to a method converted by camelCase under the same attribute of the same name as the grouping of the Client of No. For example:



PluginsAPI groupingRPC 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 documentation for RPC API:https://developers.eos.io/eosio-nodeos/reference

2.2 RPC Call Parameters

For Nodeos, some calls require passing in additional parameters, such as the get_block interface of the chain plugin, when using EosTool to make a call, just organize the parameters into an associated array, the sample code is as follows:



2.3 RPC calls return values

The return result of all RPC calls is an RpcOutput instance, and calling its hasError() method can determine whether the call is wrong, and you can further use the getError() method to obtain error information.
The response of the RPC call can be obtained through the getResult() method, which is a StdClass object converted from the original JSON result, so it can be easily extracted attribute information, such as:

2.4 Access to mainnet/testnet nodes

When creating a NodeClient instance, additional parameter executions can be passed in to define the EOS mainnet or testnet nodes to access. For example, use the following code to access a mainnet node:

Or visit a node on the Jungle testnet:


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 in the EOS software stack. However, you can access the old version of the documentation at this address:
https://developers.eos.io/eosio-nodeos/v1.1.0/reference

Use the WalletClient class to access Keosd's rpc interface. For example, the following code accesses the list_wallets interface of Keosd that runs natively:
Since Keosd's API is no longer grouped, the RPC corresponding method is directly hung on the WalletClient object, which is a difference. Like NodeClient, the call to WalletClient returns an RpcOutput object.

Keosd version 1.4 uses UNIX sockets instead of HTTP to provide RPC interfaces by default, which may be considered safer to use IPC considering that in most cases Keosd runs natively. Therefore, this is also the default instantiation option for WalletClient, and in most cases, no additional parameters need to be passed in to instantiate the WalletClient.

4. Private and public keys

EOS's key algorithm is similar to Bitcoin, but with some tweaks and defining its own format.
Use the static method of the PrivateKey class new() to generate a random private key. For example:
toEos() method is used to convert private key objects into a custom format for EOS.

4.1 Public Key Derivation
The public key can be derived from the private key, such as:


Similarly, use the toEos() method to convert the public key to a custom format for EOS.

4.2 Import EOS Private Keys
You can convert an EOS-formatted private key into an EosTool PrivateKey object, for example, the code below imports the specified EOS private key and displays its corresponding EOS public key:

4.3 Authoritative signature
PrivateKey's sign() method supports both normal signatures and authoritative signatures required by EOS nodes. For example, the following code returns a plain signature:

Pass in additional parameters to obtain an authoritative signature for the specified data:



5. Serialization
EOS requires transactions to be serialized before committing node push_transaction, which is also an unavoidable part of operating EOS transactions in PHP.
In EosTool, the Serializer class is used for serialization operations. For example, the following code serializes an EOS transfer transaction into a 16-decimal codestream format that can be submitted to an EOS node:


The static method fromAbi() of Serializer is used to construct a serializer instance based on a specified abi, and then the serialize() method of the instance is used to serialize the specified type of data to obtain a hexadecimal code stream.

6. Signature
EosTool provides two ways to sign transactions: using Keosd for signing or using a local private key.
Use the KeosdSigner class to complete the signing using the wallet server. For example:

By using the LocalSigner class, you can avoid using keosd and directly use offline private key signing. For example:
use EosTool\Signer\LocalSigner;

$prvKeys = ['5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'];
$signer = new LocalSigner($prvKeys);
$signatures = $signer->sign($tx,$pubKeys,$chainId);



7. Transaction Submission
A transaction data needs to be normalized, serialized, signed, and packaged through a series of operations before it can be submitted to the Nodeos node for broadcasting. The EosTool class provides the transact() method to isolate these tedious operations.
For example, the code below creates an EosTool instance using NodeClient and LocalSigner, and then submits a transaction:
It is convenient to change the signer to KeosdSigner, for example:


8. Invoke a single contract action
Use EosTool's pushAction() method to call a single contract action. For example, the following code calls the hi() method of the Tommy account hosting contract:



9. Deploy the contract
Deploy the contract using EosTool's setContract() method, for example:
Interested friends can go here:http://t.cn/EUZAODQ




Posted on 12/11/2018 8:59:58 AM |
Thanks Very useful
 Landlord| Posted on 12/11/2018 9:06:52 AM |

Thank you for the support.
Posted on 12/11/2018 9:11:46 AM |
I have read a lot of content on your site, and I feel that some of them are translated foreign articles
Posted on 12/11/2018 9:32:07 AM |
Look at thank you boss for getting rich
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com