WavesKit - PHP Waves Blockchain Framework

    I like PHP for its speed of development and excellent portability. This is very good when there is always a tool ready for solving problems in your pocket.


    It was rather disappointing when, when meeting with the domestic Waves Platform blockchain, there was no ready-made PHP SDK in its arsenal. Well, I had to write it.


    At first, I had to use nodes to sign transactions. So, to manage three addresses, three nodes had to be launched ... It was a miserable sight, although it did solve some problems. Until an understanding has come that relying on nodes is a dead end. Firstly, because of the limited functionality of the API , and secondly, because of the speed (in those days, the nodes were very slow).


    I started two parallel works. One is to make a blockchain browser that 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 behind the scenes of the Waves blockchain was the w8io browser . It was not easy, but it was still possible to write an independent calculation of all balances and even find an error in the calculations on the original nodes ( the bug-bounty program, by the way, works for them, they pay for the 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. Then I started by creating my own bricks for the foundation. So they were born: ABCode for encoding in base58 (actually for encoding any alphabet in any), Curve25519 for creating and checking compatible signatures (with options on steroids ), Blake2b for calculating one of the hashes (which was only available starting with PHP 7.2) etc.


    Here I have to thank Inal Kardanov for some valuable tips that directed me towards composer instead of the usual, but outdated, include files.


    After a couple of months, WavesKit saw the light , left the beta version and is now ready to work with all the standard Waves platform functionality. All transactions available on the main network can be easily created, signed and sent using just one package running on all 64-bit versions of PHP from 5.6 inclusive.


    We connect WavesKit to our 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 seed phrase from which the keys and account address are automatically calculated based on the public key. Next, we create a transfer transaction of 0.00000001 Waves from the address phrase automatically calculated by seed to the alias address "test", transfer it to the signature with a private key and send it to the network. After this, we verify 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 WavesKit documentation or immediately turn to visual examples in continuous integration tests .


    Since WavesKit has developed under real-world conditions, it already has 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 rather was confirmed and reached the required number of confirmations on the network.


    Another bulletproof mechanism is how WavesKit communicates with nodes. In greenhouse conditions, the framework only works with the main node, maintaining a constant connection with it, but in case of errors it can automatically switch to backup nodes. If you install an array of backup nodes, you can call the setBestNode function to determine the best node as the main one by the maximum value of the current height and response speed. Now add to this the internal query cache and feel the care of both users and node owners.


    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 install your callback function with the desired options and wait for new transactions that will start your processes. For example, my other VECRO project is completely built around this function, you can easily learn how it works directly in the project code .


    I like open source, this is one of the greatest achievements of mankind. Since I am the only developer and have reached the point that all my needs have been resolved, I invite you to use and contribute to WavesKit .


    Also popular now: