1

I mean not just printing data on the console, like in the documentation examples, or by get_table_rows API, but return it as function result, or maybe there is another way. The idea is that I need an action on that smart contract that will return an id for stored data when called from eosjs, and then another action that using this id will return the actual data content.

  • This doesn't sound like a clever approach to me. You want to query data from witihn a smart-contract and use the (limited) on-chain-ressources you(or the users) have to return it to some off-chain-application. But there's no need to do this from within a smart-contract so without a real reason I don't see why someone should do that. – cmadh Mar 8 at 13:01
1

If you want to get the data in eosjs you won't use the smart contract for printing because it will cost you CPU time.

A good solution is to fetch it from the get_table_rows API and then trigger an action from eosjs, that refers to the data. I would suggest using some fetching package like axios. Then you can run something like this:

axios.post(<http://{host}:{port}/v1/chain/get_table_rows>, {
  code: <name of the smart contract>,
  table: <The name of the table to query>
}).then(
 (result) => {
   // do something with result.data
   // which will look like this
   // {
   // "rows": [
   //   {
   //     "account": "account",
   //     "balance": 1000
   //   }
   // ],
   // "more": false
   //}
 }
)

Another way could be using demux-js and maintain your own database. Then you could fetch it as you want.

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.