Download the PHP package selaz/php-substrate-api without Composer
On this page you can find all versions of the php package selaz/php-substrate-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-substrate-api
php-substrate-api
PHP Substrate RPC Api
Requirement
- php >=8.0 (install ffi https://www.php.net/manual/en/intro.ffi.php)
- curl (https://www.php.net/manual/en/curl.installation.php)
- json (https://www.php.net/manual/en/json.installation.php)
- sodium (https://www.php.net/manual/en/sodium.installation.php)
- gmp (https://www.php.net/manual/en/gmp.installation.php)
- dom (https://www.php.net/manual/en/dom.installation.php)
- mbstring (https://www.php.net/manual/en/mbstring.installation.php)
Installation
If you want to install php-substrate-api in an existing project
if it is a new project
Basic Usage
Autoloading
Codec supports PSR-4
autoloaders.
RPC
-
Generate HTTP|Websocket Client
-
Read RPC Data
- Hasher
We currently support 6 hash methods, including Blake2_128,Blake2_256,Twox128,Twox256,Twox64Concat,Blake2_128Concat。
`
- Storage key
When you access storage using Substrate RPC(like rpc state_getStorage , you need to provide the key associated with the item,
- Json RPC
RPC methods that are Remote Calls available by default and allow you to interact with the actual node, query, and submit.
All rpc interface has been declare at https://github.com/gmajor-encrypt/php-substrate-api/tree/master/src/Rpc/JsonRpc
More detailed RPC documentation can be found at https://polkadot.js.org/docs/substrate/rpc
- Send extrinsics
Below is a simple example of sending a token, you can use tx.
`
Keyring
The Keyring allows you to perform operations on these keys (such as sign/verify) and never exposes the secretKey
to the outside world. Support ed25519(Edwards https://ed25519.cr.yp.to/) or sr25519( schnorrkel https://github.com/w3f/schnorrkel)
Contract
Metadata support
The metadata is used to describe a contract in a language agnostic way. Metadata can declare the storage and executable methods and types contained in the contract
We currently support ink metadata v0,v1,v2,v3,v4.
Deploy contract
After declaring a Contract class, you can call the new method to create a contract.
About how to build ink contract, you can refer to this https://docs.substrate.io/tutorials/smart-contracts/prepare-your-first-contract/
Below is an example.
Read Contract state
Reading the storage on the contract does not consume any gas, so anyone can read the contract.
You can simply read the contract through
Send Contract transaction
Sending contract transactions is very similar to executing extrinsic. You can simply exec the contract through
Generate contract address
Since the address algorithm of the contract is fixed, it is easy to calculate the deployed contract address
Example
More examples can refer to the test file https://github.com/gmajor-encrypt/php-substrate-api/tree/master/test/Rpc
Test
Troubleshooting
FFI error FFI\Exception: Failed loading '../php-substrate-api/vendor/gmajor/sr25519-bindings/src/Crypto/sr25519.so'
The current default sr25519-bindings FFI is for mac. Unfortunately, php composer currently does not support automatic compilation after install, so manual compilation is required. You can run this script
WebSocket\ConnectionException: Could not open socket to "127.0.0.1:9944"
In the test,The keyPair used in the test process is //Alice, ws://127.0.0.1:9944 is used by default as the node for testing SendTransaction. This node can start any private network settings by itself. You can also set the node address through environment variables.
gmajor/php-substrate-api v0.1.0 requires textalk/websocket dev-master -> found xxxx
but it does not match your minimum-stability
You need set minimum-stability like this "minimum-stability": "dev"
in composer.
Resources
License
The package is available as open source under the terms of the MIT License
All versions of php-substrate-api with dependencies
textalk/websocket Version dev-master
ext-curl Version *
ext-json Version *
ext-sodium Version *
gmajor/sr25519-bindings Version dev-main
tuupola/base58 Version 2.x-dev
selaz/substrate-codec-php Version dev-master
ext-gmp Version *
netresearch/jsonmapper Version dev-master