3

So the new API only accepts a packed_trx but there is no RPC call to pack a signed transaction.

How can it be done on system without cleos installed? Is there any implementation in pure Python, NodeJS or PHP?

1

3 Answers 3

1

I ended up using https://github.com/OracleChain/chainkit/blob/master/chain/packedtransaction.cpp. This is my packtx.cpp:

#include <iostream>
#include <string>
#include "chain/packedtransaction.h"
#include <QDebug>

using namespace std;

int main(int argc, char *argv[])
{
        std::string jsonString;
        jsonString = argv[1];

        SignedTransaction signedTx;

        QByteArray jsonByte = QByteArray(jsonString.c_str(), jsonString.length());

        QJsonParseError error;
        QJsonDocument doc = QJsonDocument::fromJson(jsonByte, &error);
        QJsonObject jo = doc.object();

        if (jo.isEmpty()) {
           std::cout << "JSON object is empty." << std::endl;
           return false;
        }

        QJsonValue value = jo.value(QString("transaction"));

        signedTx.fromJson(value);

        PackedTransaction packedtx(signedTx, "none");
        QJsonValue packedJson = packedtx.toJson();

        QJsonDocument tmpdoc(packedJson.toObject());
        QString strJson(tmpdoc.toJson(QJsonDocument::Compact));

        cout << strJson.toUtf8().constData() << endl;
}

You will need g++ with QT5 to compile it.

git clone https://github.com/OracleChain/chainkit
cd chainkit
rm test/main.cpp && rm utility/httpclient.cpp && rm utility/httpclient.h
vi packtx.cpp # copy&paste packtx.cpp source code
qmake -project
qmake chainkit.pro
make

Sample usage:

./chainkit '{"transaction":{"expiration": "2018-09-30T08:24:04","ref_block_num": 59970,"ref_block_prefix": 1935413997,"max_net_usage_words": 0,"max_cpu_usage_ms": 0,"delay_sec": 0,"context_free_actions": [],"actions": [{"account": "eosio.token","name": "transfer","authorization": [{"actor": "user2","permission":"active"}],"data":"00000000007115d600000000807115d601000000000000000447434e00000000046d656d6f"}],"transaction_extensions": []}}'

Sample output:

{"compression":"none","packed_context_free_data":"00","packed_trx":"4288b05b42eaed125c73000000000100a6823403ea3055000000572d3ccdcd0100000000007115d600000000a8ed32322500000000007115d600000000807115d601000000000000000447434e00000000046d656d6f00","signatures":[]}

1
  • I also had to edit the file chain/transactionheader.cpp:21 removing the + EXPIRATION_SEC as we are already giving the expiration as future date.
    – Gotenks
    Commented Nov 21, 2018 at 17:05
0

RPC API could be helpful https://developers.eos.io/eosio-nodeos/reference#get_info For this is API, you need to forward an API point

0

You can use eosjs to process transaction. here is link https://github.com/EOSIO/eosjs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.