WavesKit — PHP framework for working with Waves Platform

    I like PHP for development speed and excellent portability. It's great to have such a tool in your pocket, always ready to solve problems.

    For me it was quite sad that there was no Waves Platform SDK for PHP when i first met this nice blockchain. Well, I had to write such kit.

    At first i even used my nodes to sign transactions. So for 3 addresses to operate i had to run 3 nodes… It was pretty pathetic, but solved some tasks. Until there was an understanding that relying on a node is a dead end. Firstly because of the lack of functionality and secondly node API is slow (in those days was super slow).

    I started 2 parallel works. The one is a blockchain explorer which must be fast and don't rely on node API at all. The other one is an aggregator of all functions needed to work with Waves Platform. This is how projects such as w8io and WavesKit were born.

    The first step behind the scenes of Waves blockchain was w8io explorer. It was tough, but i still managed to write an independent calculation of all balances and even found an error in the calculations on the original nodes (by the way, bug-bounty program works, they pay for errors). You can learn more about w8io explorer functionality in this topic: https://forum.wavesplatform.com/t/w8io-waves-explorer-based-on-php-sqlite

    When it was done i proceeded to the next step, but could not find building blocks, and even for the most important part, the cryptographical. So i started making my own base packages. This is how were born ABCode for base58 encoding (mostly but any to any alphabet actually), Curve25519 for supported variants of sign and verify functions (on steroids variants), Blake2b for hash function (which is only appeared in Sodium library in PHP 7.2), etc.

    Here i should thank Inal Kardanov for a couple of tips that guided me to the composer way instead of old school file includes.

    A couple of months later WavesKit came out of beta stage and now it's ready to work with standard Waves Platform functionality. All mainnet transactions are available for users to create, sign and broadcast easily in the single package, which is working on every 64-bit version of PHP starting from 5.6 inclusive.

    Connect WavesKit to your project:

    composer require deemru/waveskit

    Basic usage example:

    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 WavesKit object, which works in testnet "T". We set seed pharse, from which keys and address from public key calculate automatically. Next, we create a transfer transaction of 0.00000001 Waves from the calculated address to an address with the alias "test", pass this transaction to sign with the calculated private key function and broadcast it to the network. After that, we ensure that the transaction is successfully confirmed by the network.

    Working with transactions is concentrated in functions with "tx" prefixes. For a better understanding of how to work with transactions, you can study WavesKit documentation or immediately refer to real usage examples in continuous integration tests.

    Since WavesKit was evolving on real cases, it has advanced features. First of all, it is ensure function that can be used to achieve any desired level of confidence that your transaction wasn't lost, but confirmed and reached the required number of confirmations.

    Another bullet proof mechanism is how it interacts with nodes. There is an internal ability of fallback to backup nodes in case of main node errors. You can set an array of backup nodes to fallback. You can call setBestNode function to automatically choose the best currently suitable node based on the highest height and the shortest response time of the node. Now add an internal cache mechanic and connection holding to its arsenal and you can feel the care not only about users, but node owners too.

    One of the latest advanced feature is txMonitor function. It appeared as a necessity to react on incoming transactions in real time. This function fully resolves all issues around transaction processing in the blockchain. No more developers pain, just set your callback function and desired options and wait for new transactions to trigger your processes. For example, my VECRO project is fully based around this txMonitor function, feel free to learn how it works.

    I like open source, this is one of the greatest achievements of mankind. Since i am the only developer of this framework and has come to the point that all my needs are solved, i welcome you to use and contribute to WavesKit.

    Also popular now: