2

I'd like to make a simple action in the format of cleos push transaction.

Motivation: DApps often need transactions with multiple actions, which can't be done with cleos push action. So the natural learning path to do that is to first do a cleos push transaction with a single concrete action, and then learn how to cleos push transaction with multiple actions (which will likely be trivial).


For example, I can write

cleos --url api.eosnewyork.io push action eosio.token transfer '["useraccount1", "useraccount2", "0.0001 EOS", ""]' -p useraccount1@active

How do I say exactly the same in the push transaction format?

The example at what seems to be the official docs is annoyingly empty.


My attempt so far is:

cleos --url api.eosnewyork.io push transaction '{"actions": [{"account": "eosio.token", "name": "transfer", "authorization": [{"actor": "useraccount1", "permission": "active"}], "data": "{\"from\": \"useraccount1\", \"to\": \"useraccount2\", \"quantity\": \"0.0001 EOS\", \"memo\": \"\"}"}]}' push transaction '{"actions": [{"account": "eosio.token", "name": "transfer", "authorization": [{"actor": "useraccount1", "permission": "active"}], "data": "{\"from\": \"useraccount1\", \"to\": \"useraccount2\", \"quantity\": \"0.0001 EOS\", \"memo\": \"\"}"}]}'

To which cleos replies Invalid hex character: {. It seems to suggest that the "data" string should be in hexadecimal form. In desperation, I tried to just convert the data string to hexadecimal (with " instead of \"), like this:

cleos --url api.eosnewyork.io push transaction '{"actions": [{"account": "eosio.token", "name": "transfer", "authorization": [{"actor": "useraccount1", "permission": "active"}], "data": "{\"from\": \"useraccount1\", \"to\": \"useraccount2\", \"quantity\": \"0.0001 EOS\", \"memo\": \"\"}"}]}' push transaction '{"actions": [{"account": "eosio.token", "name": "transfer", "authorization": [{"actor": "useraccount1", "permission": "active"}], "data": "7b2266726f6d223a2022757365726163636f756e7431222c2022746f223a2022757365726163636f756e7432222c20227175616e74697479223a2022302e3030303120454f53222c20226d656d6f223a2022227d"}"}]}'

Then the server at api.eosnewyork.io says Error 3040005: Expired Transaction, and e.g. the server at api1.eosdublin.io says Error 3200006: invalid http request.

  • 1
    What's wrong with this cleos --url api.eosnewyork.io push action eosio.token transfer '["useraccount1", "useraccount2", "0.0001 EOS", ""]' -p useraccount1@active – Lei Kan Sep 11 '18 at 3:36
  • @LeiKan That works fine. But dapps often need transactions with multiple actions, which can't be done with cleos push action. So I'd like to be able to do cleos push transaction with a single concrete action, as the hardest step in learning how to cleos push transaction with multiple actions (which seems trivial then). I've added this to the body of the question. – Gassa Sep 11 '18 at 9:31
  • 3
    I haven't try push transaction, but I think you could use cleos --print-request --dont-broadcast to get the transaction json. Then you could submit the transaction json content. – Lei Kan Sep 12 '18 at 8:50
  • If your transaction need multiple action at a time you can can handle that with approach mentioned by Lei Kan.You need to create a new action and call the actions you want to use simultaneously, So now you need to push only the newly created action. – Nirdesh Kumar Choudhary Sep 14 '18 at 5:43
  • 1
    @LeiKan yay, this approach was helpful, thanks! Are you interested in writing a full answer? If not, I'll write one myself. – Gassa Sep 25 '18 at 19:43
1

I have created text file with the following inside:

{
  "actions": [
    {   
      "account": "eosio",
      "name": "newaccount",
      "authorization": [
        {
          "actor": "youraccount",
          "permission": "active",
        }
      ],  
      "data": {
        "creator": "youraccount",
        "name": "yournewaccount",
        "owner": {
          "threshold": 1,
          "keys": [
            {
              "key": "EOS5NH5qF4zS5Z336Djs1xvXjYgWxe47jbrRL6ZCkPgDf6QsfzUrJ",
              "weight": 1,
            }
          ],
          "accounts": [], 
          "waits": [], 
        },
        "active": {
          "threshold": 1,
          "keys": [
            {
              "key": "EOS5NH5qF4zS5Z336Djs1xvXjYgWxe47jbrRL6ZCkPgDf6QsfzUrJ",
              "weight": 1,
            }   
          ],
          "accounts": [], 
          "waits": [], 
        },  
      },  
    },  
  ],  
}

and run
cleos push transaction file.txt

** Note that you can write multiple actions.

  • Glad that it works now, and thanks for the answer! At the time of the question though, data could have been given to cleos only in binary (encoded) form. – Gassa Sep 18 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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