1

Has anyone ever pushed an array of transactions using the cleos push transactions command? If so, can you show how you prepared the transaction array JSON and a working example of the command being used?

1
  • Is there something that I left out to be considered a working solution? I could edit the answer to literally just show the format of the tx and pushing it. Figured crafting the actions provided a little more context Commented Aug 27, 2019 at 1:51

1 Answer 1

0

Note: This is kind of a weird workaround since cleos doesn't currently support signing and pushing multiple transactions in a simple manner. The following answer requires jq command line json parsing library.

The following example will generate, sign, and broadcast 2 transactions using cleos push transactions.

cleos push transactions "$(echo "$(cleos push action eosio.token transfer '{"from":"user11111111","to":"user22222222","quantity":"1.0000 EOS","memo":"tx1"}' -d -p user11111111 --return-packed)" "$(cleos push action eosio.token transfer '{"from":"user11111111","to":"user22222222","quantity":"1.0000 EOS","memo":"tx2"}' -d -p user11111111 --return-packed)" | jq -s '.[0] += .[0]')"

There's a bit here, so let's break it down...

The main command is cleos push transactions "$(...)". This tells cleos that we are going to provide a raw transaction that is already signed and packed, and push it to the blockchain.

The rest of the command is a one-liner that is forming the packed and signed multi-transaction json.

The command inside the evaluator, will echo the output of the commands that follow it, then parse that through jq. Eg.. echo "$(command1)" "$(command2)" | jq ...

The first transaction is created with the following: cleos push action eosio.token transfer '{"from":"user11111111","to":"user22222222","quantity":"1.0000 EOS","memo":"tx1"}' -d -p user11111111 --return-packed

And the second transaction is created with the following: cleos push action eosio.token transfer '{"from":"user11111111","to":"user22222222","quantity":"1.0000 EOS","memo":"tx2"}' -d -p user11111111 --return-packed

These commands will prepare a transaction with a single action. It will sign but will not broadcast (-d); the packed transaction result will be returned to STDOUT. To combine them together, we use jq below...

| jq -s '.[0] += .[0]'

So remember how we did echo "$(command1) $(command2) above, well jq can combine their output together. The parser command above is telling jq to combine the two transaction objects into a single array.

All of that should give us a result that looks similar to the following:

[
  {
    "signatures": [
      "SIG_K1_K7eWqZmnneUHhnhcR9r6LwNnXYSEqpv6HcE124nNfSL5eZADyTDGfXTprxH79cMgh74GAX5Fo9mYiiJQxCMp2cN8hSept7"
    ],
    "compression": "none",
    "packed_context_free_data": "",
    "packed_trx": "822f5e5d94f08b818c41000000000100a6823403ea3055000000572d3ccdcd0100000857219de8ad00000000a8ed32322400000857219de8ad00001057219de8ad102700000000000004454f53000000000374783100"
  },
  {
    "signatures": [
      "SIG_K1_Jz64RXE4FiX7VeDo9XacR2pGKbmN4uGygXy5ghwrUwyTDPN5ApyY4oc7RMkWSPpZmwzkStdUWUx4ZzNetWcV12E6KPBb2k"
    ],
    "compression": "none",
    "packed_context_free_data": "",
    "packed_trx": "832f5e5d94f08b818c41000000000100a6823403ea3055000000572d3ccdcd0100000857219de8ad00000000a8ed32322400000857219de8ad00001057219de8ad102700000000000004454f53000000000374783200"
  }
]

This is perfectly formatted for the cleos push transactions $(...) command.

1
  • 1
    Well that was definitely my screw up. I saw transactions and read actions. I have since updated the answer to reflect the desired multiple transactions. However, I still use cleos push action to craft the transactions in this example. You could always craft the transaction by hand or some other method and then use cleos to sign/broadcast. Commented Aug 22, 2019 at 6:04

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.