I like PHP for development speed and excellent portability. This is very good when there is always a tool ready for problem solving in your pocket.
It was rather disappointing when, when meeting the Wales Platform blockchain in our country, there was no PHP ready SDK in its arsenal. Well, I had to write it.
At first, I had to use nodes to sign transactions. So, to manage the three addresses had to run three nodes ... It was a pitiful sight, although it solved some problems. Until the understanding has come that to rely on nodes is a dead end. Firstly, because of the limited API functionality, and secondly, because of the speed (in those days the nodes were very slow).
I started two parallel works. One is to make the blockchain browser, which will be fast and completely independent of the API nodes. The second is to collect all the functions for working with the Waves Platform in one place. So there were projects w8io and WavesKit .
The first step backstage at the Waves blockchain was the w8io browser . It was not easy, but still managed to write an independent calculation of all balances and even find an error in the calculations on the original nodes ( the bug-bounty program works by the way, they pay for errors found). You can learn more about the w8io browser functionality in this topic: https://forum.wavesplatform.com/t/w8io-waves-explorer-based-on-php-sqlite
In the process of working on w8io, I already had doubts, but when the work came to a logical end and I started creating the SDK, the doubts were confirmed. I could not find some functions anywhere, including the most important, cryptographic ones. Then I started by building my own bricks for the foundation. So were born: ABCode for encoding in base58 (actually for encoding any alphabet in any), Curve25519 for creating and verifying compatible signatures (with options on steroids ), Blake2b for calculating one of the hashes (which was available only since PHP 7.2) etc.
Here I have to thank Inal Kardanov for some valuable advice that sent me towards the composer instead of the usual for me, but obsolete, include files.
After a couple of months, WavesKit saw the light , came out of the beta version and is now ready to work with all the standard functionality of the Waves platform. All transactions available on the core network can be easily created, signed and sent by just one package running on all 64-bit PHP versions from 5.6 inclusive.
We connect WavesKit to your project:
composer require deemru/waveskit
We use:
use deemru\WavesKit; $wk = new WavesKit( 'T' ); $wk->setSeed( 'manage manual recall harvest series desert melt police rose hollow moral pledge kitten position add' ); $tx = $wk->txBroadcast( $wk->txSign( $wk->txTransfer( 'test', 1 ) ) ); $tx = $wk->ensure( $tx );
In the example above, we create a WavesKit object that runs on the test network "T". Set the led phrase, from which the keys and the address of the account are automatically calculated based on the public key. Next, we create a transfer transaction 0.00000001 Waves with the address automatically calculated by the phrase phrase to the alias address "test", transfer it to the signature with the private key and send it to the network. After that we are convinced that the transaction has been successfully confirmed by the network.
Work with transactions is concentrated in functions starting with tx . For a better understanding of working with transactions, you can study the documentation of WavesKit or immediately refer to illustrative examples in tests of continuous integration .
Since WavesKit was developing in terms of real use, it already had advanced features. The first killer feature is the ensure function , which controls the achievement of the required level of confidence that the transaction was not lost, but, on the contrary, was confirmed and reached the required number of confirmations on the network.
Another bulletproof mechanism is how WavesKit communicates with nodes. Under greenhouse conditions, the framework works only with the main node, maintaining a permanent connection with it, but in case of errors it can automatically switch to the backup ones. If you set up an array of backup nodes, you can call the setBestNode function to determine the best node as the primary one based on the maximum value of the current height and response speed. Now add to this the internal query cache and feel the care of both the users and the owners of the nodes.
One of the latest advanced mechanisms is the txMonitor function. She appeared in connection with the need to respond to incoming transactions in real time. This function completely solves all the nuances associated with processing transactions in the blockchain. No more pain, just set up your callback function with the desired options and wait for new transactions that will start your processes. For example, another of my VECRO projects is completely built around this function, you can easily study how it works right in the project code .
I like open source, this is one of the greatest achievements of humanity. Since I am the only developer and have reached the state that all my needs are resolved, I invite you to use and contribute to WavesKit .
Source: https://habr.com/ru/post/446110/
All Articles