3

Is there a way to receive the return output of an action with EOSJS? Say for example I have an action that reads columns from a table, sums a row and returns the result. How would I structure the function in C++ so that it returns the result, and how would I process the result in an EOSJS call?

1 Answer 1

8

You have several ways to retrieve data from eos chain as i know. They differs a lot, so you should find a better one for you case.

#1. Get from table
As you noted there is getTableRows method in eosjs lib, and by default it returns packed response. You can pass option json: true to instruct library to unpack response for you.

eos.getTableRows({
    code:'CONTRACT_NAME',
    scope:'SCOPE_ACCOUNT (Normally contract)',
    table:'TABLE_NAME',
    json: true,
}).then(function(res) {
    console.log(res);
});

You can find other available options in json format definition

#2. Read execution logs
You can log some valuable info to "console" when your action is executed. Then to read those logs call getActions method from eosjs lib. It return a list of actions for specific account. See json definition for more info.

this.eos.getActions('CONTRACT_NAME').then(...)

Note #1: Make sure that node you query from is running with history_api_plugin and filter_on_accounts option in config file respect your CONTRACT_NAME.

Note #2: Api returns every action that somehow belongs to provided account. So you need to filter them to find interesting one (use transaction_id received when transaction submitted).

There also a possible ways using mongodb plugin, but i can't provide any more info on this.

1
  • Thank you! Just discovered the json:true last night and was just writing an answer now. Yours is much better though, I'll make it the official answer now. Jun 1, 2018 at 5:07

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.