Skip to content

Transactions/Broadcast

Compare
Choose a tag to compare
@t3ran13 t3ran13 released this 06 Dec 17:45
· 151 commits to master since this release

In Release

  • broadcast (example for vote)
  • tools for broadcast
  • bag fixes for broadcast commands

Install Via Composer

For readonly, without broadcast

composer require t3ran13/php-graphene-node-client

with broadcast (sending transactions to blockchain)

(details and dockerfile here)

install components

  • automake
  • libtool
  • libgmp-dev

install extensions

  • secp256k1 (how to install (secp256k1-php)[https://github.com/Bit-Wasp/secp256k1-php])
  • gmp

broadcast_api operations templates

  • vote
<?php

use GrapheneNodeClient\Tools\ChainOperations\OpVote;
use GrapheneNodeClient\Tools\Transaction;

$answer = OpVote::doSynchronous(
    Transaction::CHAIN_STEEM, //Transaction::CHAIN_GOLOS
    'guest123',
    '5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg',
    'firepower',
    'steemit-veni-vidi-vici-steemfest-2016-together-we-made-it-happen-thank-you-steemians',
    10000
);

// example of answer
//Array
//(
//    [id] => 5
//    [result] => Array
//        (
//            [id] => a2c52988ea870e446480782ff046994de2666e0d
//            [block_num] => 17852337
//            [trx_num] => 1
//            [expired] =>
//        )
//
//)

Transaction for blockchain (broadcast)

<?php

use GrapheneNodeClient\Tools\Transaction;

/** @var CommandQueryData $tx */
$tx = Transaction::init($chainName);
$tx->setParamByKey(
    '0:operations:0',
    [
        'vote',
        [
            'voter'    => $voter,
            'author'   => $author,
            'permlink' => $permlink,
            'weight'   => $weight
        ]
    ]
);

if (Transaction::CHAIN_GOLOS === $chainName) {
    $connector = new GolosWSConnector();
} elseif (Transaction::CHAIN_STEEM === $chainName) {
    $connector = new SteemitWSConnector();
}
$command = new BroadcastTransactionSynchronousCommand($connector);
Transaction::sign($chainName, $tx, ['posting' => $publicWif]);

$answer = $command->execute(
    $tx
);

WARNING

Transactions are signing with spec256k1-php with function secp256k1_ecdsa_sign_recoverable($context, $signatureRec, $msg32, $privateKey) and if it is not canonical from first time, you have to make transaction for other block. For searching canonical sign function have to implement two more parameters, but spec256k1-php library does not have it.