As part of our Block Producer commitment to the community, we want to focus on building tools/applications that will help increase adoption of the EOS platform. As with most large applications, there can be a high barrier to entry when you have little or outdated documentation and a lack of tools to help you get started.

To save budding EOS developers some time, we’ve put together a PHP SDK that covers most OF the EOS API methods. In the documentation, each call has some examples that contain the actual output of the API.

Whether you use PHP or not, we hope this will be a useful reference point to start building your first application, or just get to know what the EOS blockchain API has to offer.

You can check out the EOS official documentation, but be aware of the lack of newer methods. In addition, some of the examples in these documents use outdated syntax.

The installation

composer require block-matrix-network/php-eos-rpc-sdk
Copy the code

Set up the

Create a dotenv. env file in the project root directory using your favorite RPC API host. You can use.env.example as a template:

cp .env.example .env
Copy the code

usage

There is a factory method to automatically instantiate all dependencies:

$api = (new ChainFactory)->api();
Copy the code

The sample

To help you get started, there is a simple example runner that covers all API commands.

Simply run this command through the CLI to see sample output for all commands:

cd examples
php chain.php
Copy the code

API methods

Covers all read-only EOS blockchain API methods. Here are a few examples:

GetInfo Gets the information

Get the latest information about the node.

echo $api->getInfo(); { "server_version": "db031363", "chain_id": "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906", "head_block_num": 1380988, "last_irreversible_block_num": 1380657, "last_irreversible_block_id": "0015113163cbe7676c4e56d1758a1ce95e47fa645827b9202de5753031d36b8b", "head_block_id": "0015127c94676db3da55ec66210952db7f4db35b0e731abefff1562c201a0666", "head_block_time": "The 2018-06-18 T15:38:45. 000", "head_block_producer" : "eoscannonchn", "virtual_block_cpu_limit" : 200000000, "virtual_block_net_limit": 1048576000, "block_cpu_limit": 199900, "block_net_limit": 1048576 }Copy the code

GetBlock Gets block information

Get block-related information.

echo $api->getBlock("1337"); {"timestamp": "2018-06-09t12:09:21.500 ", "producer":" eoSIo ", "confirmed": 0, "previous": "00000538b374c1cbfaeed7253ad3075ddc72a28f0a0515301fc1bbed675f2316", "transaction_mroot": "0000000000000000000000000000000000000000000000000000000000000000", "action_mroot": "bcb9763baa3bbf98ed36379b4be0ecb2d9cd21c75df01729c63b2b021001c10c", "schedule_version": 0, "new_producers": null, "header_extensions": [ ], "producer_signature": "SIG_K1_K5jWf36t6j454Hb2fGuV37YTwMTvuQ51ZPBtpru8Ud2axtMTEauWyvtpJuTpnvqzReUndDgEDXvoeEP4jdj2bpnYKBt6g2", "transactions": [ ], "block_extensions": [ ], "id": "00000539d17a03af7126e073be4c4d99a72b7f58793cf2c87b9bfd41b6c711fb", "block_num": 1337, "ref_block_prefix": 1944069745 }Copy the code

GetCode gets the code

Get the smart contract code.

echo $api->getCode("eosio.token"); { "account_name": "eosio.token", "code_hash": "3e0cf4172ab025f9fff5f1db11ee8a34d44779492e1d668ae1dc2d129e865348", "wast": "(module\n (type $0 (func (param i32 i64 i32)))\n (type $1 (func (param i32 i64 i64 i32 i32)))\n (type $2 (func (param i32 i64 i32 i32)))\n (type $3 (func ))\n (type $4 (func (result i64)))\n (type $5 (func (param i64 i64)))\n (type $6 (func (param i64)))\n (type $7 (func (param i32 i32)))\n (type $8 (func (param i64 i64 i64 i64) (result i32)))\n (type $9 (func (param i64 i64 i64 i64 i32 i32) (result i32)))\n (type $10 (func (param i32 i32 i32) (result i32)))\n (type $11  (func (param i64) (result i32)))\n (type $12 (func (param i32)))\n (type $13 (func (result i32)))\n (type $14 (func (param i32 i32) (result i32)))\n (type $15 (func (param i32) (result i32)))\n (type $16 (func (param i32 i32 i32 i32)))\n (type $17 (func (param i32 i64 i32 i64)))\n (type $18 (func (param i64 i64 i32 i32)))\n (type $19 (func (param i32 i64 i32) (result i32)))\n (type $20 (func (param i64 i64 i64)))\n (import \"env\" \"abort\" (func $23 ))\n (import \"env\" \"action_data_size\" (func $24 (result i32)))\n (import \"env\" \"current_receiver\" (func $25 (result i64)))\n (import \"env\" \"current_time\" (func $26 (result i64)))\n (import \"env\" \"db_find_i64\" (func $27 (param i64 i64 i64  i64) (result i32)))\n ...... (export \"_ZN5eosio5token5issueEyNS_5assetENSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE\" (func $51))\n (export \"_ZN5eosio5token11add_balanceEyNS_5assetEy\" (func $52))\n ........... $block2\n get_local $3\n i32.const 12\n i32.add\n tee_local $3\n get_local $1\n i32.lt_u\n br_if $loop\n end ;; $loop\n end ;; $block1\n return\n end ;; $block\n get_local $0\n i32.const -4\n i32.add\n tee_local $3\n get_local $3\n i32.load\n i32.const 2147483647\n I32. And \ n i32. Store \ n \ n \ n \ n (func $87 unreachable \ n)), "" wasm" : ""," abi ": {" version" : "eosio: : abi \ / 1.0", "types" : [ { "new_type_name": "account_name", "type": "name" } ], "structs": [ { "name": "transfer", "base": "", "fields": [ { "name": "from", "type": "account_name" }, { "name": "to", "type": "account_name" }, { "name": "quantity", "type": "asset" }, { "name": "memo", "type": "string" } ] }, { "name": "create", "base": "", "fields": [ { "name": "issuer", "type": "account_name" }, { "name": "maximum_supply", "type": "asset" } ] }, { "name": "issue", "base": "", "fields": [ { "name": "to", "type": "account_name" }, { "name": "quantity", "type": "asset" }, { "name": "memo", "type": "string" } ] }, { "name": "account", "base": "", "fields": [ { "name": "balance", "type": "asset" } ] }, { "name": "currency_stats", "base": "", "fields": [ { "name": "supply", "type": "asset" }, { "name": "max_supply", "type": "asset" }, { "name": "issuer", "type": "account_name" } ] } ], "actions": [ { "name": "transfer", "type": "transfer", "ricardian_contract": "## Transfer Terms & Conditions\n\nI, {{from}}, certify the following to be true to the best of my knowledge:\n\n1. I certify that {{quantity}} is not the proceeds of fraudulent or violent activities.\n2. I certify that, to the best of my knowledge, {{to}} is not supporting initiation of violence against others.\n3. I have disclosed any contractual terms & conditions with respect to {{quantity}} to {{to}}.\n\nI understand that funds transfers are not reversible after the {{transaction.delay}} seconds or other delay as configured by {{from}}'s permissions.\n\nIf this action fails to be irreversibly confirmed after receiving goods or services from '{{to}}', I agree to either return the goods or services or resend {{quantity}} in a timely manner.\n" }, { "name": "issue", "type": "issue", "ricardian_contract": "" }, { "name": "create", "type": "create", "ricardian_contract": "" } ], "tables": [ { "name": "accounts", "index_type": "i64", "key_names": [ "currency" ], "key_types": [ "uint64" ], "type": "account" }, { "name": "stat", "index_type": "i64", "key_names": [ "currency" ], "key_types": [ "uint64" ], "type": "currency_stats" } ], "ricardian_clauses": [], "error_messages": [], "abi_extensions": [] } }Copy the code

GetCurrencyBalance Gets the currency balance

Gets the monetary balance of the account.

echo $api->getCurrencyBalance("eosio.token", "eosdacserver"); [" EOS "2453.2054]Copy the code

test

To run the test suite, simply execute:

vendor/bin/phpunit
Copy the code

Check out the Github repository for more content.

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Share some interactive online programming tutorials related to blockchain such as Ethereum, EOS and Bitcoin:

  • This course will help you get a quick start on the development of EOS blockchain decentralized applications. It covers core knowledge points such as EOS tool chain, account and wallet, issuing tokens, development and deployment of smart contracts, and interaction between codes and smart contracts. Finally, the development of a notepad DApp will be completed using all knowledge points comprehensively.
  • Java Ethereum development tutorial, mainly for Java and Android programmers for blockchain Ethereum development web3J details.
  • Python Ethereum is a detailed explanation of blockchain ethereum development by Python engineers using Web3.py.
  • PHP Ethereum, mainly introduces the use of PHP for smart contract development interaction, account creation, transactions, transfers, token development, filters and transactions and other content.
  • Ethereum introductory course, mainly introduces smart contract and DAPP application development, suitable for entry.
  • Ethereum development advanced tutorial, mainly introduces the use of Node.js, mongodb, blockchain, IPFS to achieve decentralized e-commerce DApp combat, suitable for advanced.
  • C# ethereum, mainly explains how to use C# based development. Net ethereum applications, including account management, status and transactions, smart contract development and interaction, filters and transactions, etc.
  • Java development tutorial COINS, this course for beginners, content covers the core concepts of COINS, such as block mechanism, key chain store, decentralized consensus and script, trading and UTXO etc, also explained how to integrate the currency support functions in Java code, such as creating address wallet, tectonic naked trading, management, Is a rare bitcoin development course for Java engineers.
  • PHP currency development tutorial, this course for beginners, content covers the core concepts of COINS, such as block mechanism, key chain store, decentralized consensus and script, trading and UTXO etc, also explained how to integrated the currency support functions in PHP code, such as creating address wallet, tectonic naked trading, management, This is a rare bitcoin development course for Php engineers.
  • Tendermint blockchain development in detail, this course is suitable for engineers who want to use Tendermint blockchain development, the course content includes the core concepts of tendermint application development model, such as ABCI interface, Merkle tree, multi-version state library, etc., also includes the rich practical code such as token issuance. It is the best choice for go language engineers to quickly start blockchain development.

Huizhi net original translation, reprint please indicate the source. Here is a PHP SDK package for the EOS blockchain RPC API