0

I used the following function to get transaction with eosjs, but it doesn't display all the content.

(async () => {
  await rpc.history_get_transaction('188d9cba22eb1acbeff074d9c092b202808c1510f37b02798c286d00c9cc7b5d', 46632826)
})();

How can we get the value of the attribute "actions : [Array]" with eosjs.

 {
 id: '188d9cba22eb1acbeff074d9c092b202808c1510f37b02798c286d00c9cc7b5d',
 trx: {
   receipt: {
     status: 'executed',
     cpu_usage_us: 344,
     net_usage_words: 19,
     trx: [Array]
   },
   trx: {
     expiration: '2020-02-27T03:36:29',
     ref_block_num: 1126,
     ref_block_prefix: 2779202260,
     max_net_usage_words: 0,
     max_cpu_usage_ms: 0,
     delay_sec: 0,
     context_free_actions: [],
     actions: [Array],
     transaction_extensions: [],
     signatures: [Array],
     context_free_data: []
   }
 },

1 Answer 1

0

You can access the JSON Object like this:

(async () => {
    let transaction = await rpc.history_get_transaction('188d9cba22eb1acbeff074d9c092b202808c1510f37b02798c286d00c9cc7b5d', 46632826);
    let actions = transaction.trx.trx.actions; // <---- All actions
    console.log("actions", actions);
    if (actions.length >= 1) {
        console.log("first action", actions[0]); // <---- First action
        console.log("stringified first action", JSON.stringify(actions[0])); // <---- First action, but as a string and not json object
    }
})();

Here is some more information about JSON: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON

2
  • Thank you for your answer Frank.
    – Emilien
    Mar 4, 2020 at 3:25
  • I have a question, my smart contract has only one action, does that mean that the transaction contains only one action. The idea is that every time I call the action in my smart contract, the transaction ID back is stored in a database. Once I need this data, I receive a transaction with the ID, so how do I know the rank of my action in the list of actions.
    – Emilien
    Mar 11, 2020 at 0:40

Your Answer

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

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