0

I have a problem with pushing transaction on blockchain, I think the problem is with the serialization of packed_trx. There is not enough info about it. So basically I took this JSON object below and converted it into hex.

{
  "compression": "none",
  "transaction": {
    "expiration": "2018-12-13T14:07:32",
    "ref_block_num": 32055469,
    "ref_block_prefix": 1753012779,
    "context_free_actions": [],
    "actions": [
        {
            "account": "decentwitter",
            "name": "tweet",
            "authorization": [
                {
                    "actor": "ysignchatapp",
                    "permission": "active"
                }
            ],
            "data": "0000000000ea305500000000487a2b9d102700000000000004454f53000000001163726561746564206279206e6f70726f6d"
        }
    ],
    "transaction_extensions": []
  },
  "signatures": [
        "...my signature..."
   ]
}

Is this right way of doing it?

0

Updated Answer for producing Transaction:

From the eosjs docs:

https://github.com/EOSIO/eosjs

You would hard code a key for dev purposes like so:

const defaultPrivateKey = "5JtUScZK2XEp3g9gh7F8bwtPTRAkASmNrrftmx4AxDKD5K4zDnr"; // useraaaaaaaa
const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);

You would define a transaction like this:

(async () => {
  const result = await api.transact({
    actions: [{
      account: 'eosio.token',
      name: 'transfer',
      authorization: [{
        actor: 'useraaaaaaaa',
        permission: 'active',
      }],
      data: {
        from: 'useraaaaaaaa',
        to: 'useraaaaaaab',
        quantity: '0.0001 SYS',
        memo: '',
      },
    }]
  }, {
    blocksBehind: 3,
    expireSeconds: 30,
  });
  console.dir(result);
})();

And the API will handle producing the transaction with the signature that is compatible with the RPC API.

I have an example of how I integrated with Scatter if you would like an example of that: https://github.com/NatPDeveloper/eos-permission-viewer/blob/test/src/components/navigation.js#L77


Here's an example of how to create the json for a transaction then send that json file with cleos push transaction


Start with cleos by creating the json for each action, as follows (example uses transfer):

cleos [whatever logic for actions your trying to send here] -s -d -j

Flags:

-s,--skip-sign              Specify if unlocked wallet keys should be used to sign transaction
-d,--dont-broadcast         don't broadcast transaction to the network (just print to stdout)
-j,--json                   print result as json

This creates json output do this for all the transactions:

{
  "expiration": "2018-10-20T10:54:37",
    "ref_block_num": 92,
    "ref_block_prefix": 276911189,
    "max_net_usage_words": 0,
    "max_cpu_usage_ms": 0,
    "delay_sec": 0,
    "context_free_actions": [],
    "actions": [{
      "account": "eosio.token",
      "name": "transfer",
      "authorization": [{
        "actor": "fromaccount",
        "permission": "active"
      }
      ],
      "data": "00f2d4142123e95d0040c85353840ccd102700000000000004454f5300000000046d656d6f"
    }
    ],
    "transaction_extensions": [],
    "signatures": [],
    "context_free_data": []
}

{
  "expiration": "2018-10-20T10:54:42",
    "ref_block_num": 102,
    "ref_block_prefix": 3271438144,
    "max_net_usage_words": 0,
    "max_cpu_usage_ms": 0,
    "delay_sec": 0,
    "context_free_actions": [],
    "actions": [{
      "account": "eosio.token",
      "name": "transfer",
      "authorization": [{
        "actor": "fromaccount",
        "permission": "active"
      }
      ],
      "data": "00f2d4142123e95d0080c85353840ccd102700000000000004454f5300000000046d656d6f"
    }
    ],
    "transaction_extensions": [],
    "signatures": [],
    "context_free_data": []
}

{
  "expiration": "2018-10-20T10:54:45",
    "ref_block_num": 109,
    "ref_block_prefix": 718898287,
    "max_net_usage_words": 0,
    "max_cpu_usage_ms": 0,
    "delay_sec": 0,
    "context_free_actions": [],
    "actions": [{
      "account": "eosio.token",
      "name": "transfer",
      "authorization": [{
        "actor": "fromaccount",
        "permission": "active"
      }
      ],
      "data": "00f2d4142123e95d00c0c85353840ccd102700000000000004454f5300000000046d656d6f"
    }
    ],
    "transaction_extensions": [],
    "signatures": [],
    "context_free_data": []
}

To make this into one transaction, copy and paste each of the actions (an array of actions) into the first json output, like so:

{
  "expiration": "2018-10-20T10:54:37",
    "ref_block_num": 92,
    "ref_block_prefix": 276911189,
    "max_net_usage_words": 0,
    "max_cpu_usage_ms": 0,
    "delay_sec": 0,
    "context_free_actions": [],
    "actions": [{
      "account": "eosio.token",
      "name": "transfer",
      "authorization": [{
        "actor": "fromaccount",
        "permission": "active"
      }
      ],
      "data": "00f2d4142123e95d0040c85353840ccd102700000000000004454f5300000000046d656d6f"
    },{
      "account": "eosio.token",
      "name": "transfer",
      "authorization": [{
        "actor": "fromaccount",
        "permission": "active"
      }
      ],
      "data": "00f2d4142123e95d0080c85353840ccd102700000000000004454f5300000000046d656d6f"
    },{
      "account": "eosio.token",
      "name": "transfer",
      "authorization": [{
        "actor": "fromaccount",
        "permission": "active"
      }
      ],
      "data": "00f2d4142123e95d00c0c85353840ccd102700000000000004454f5300000000046d656d6f"
    }
    ],
    "transaction_extensions": [],
    "signatures": [],
    "context_free_data": []
}

Finally, save this json file, and execute it as follows (be sure wallet is open and unlocked):

cleos push transaction ./test.json
  • Thanks for the answer, but I think that is not what I needed. I am trying to make the android wallet, which communicates through API directly without cleos. So what I need is exact algorithm how is data generated and how to send that JSON to /push_transaction. – Deda Dec 17 '18 at 10:24
  • Ah okay. You don't want to handle that logic yourself, use eosjs for that. I've updated my answer. – Nat Dec 17 '18 at 11: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.