Store contract results tag in a variable

0 votes

I have a web3 contstant look like this.

const test = contract_instance.methods.getPost(15).call().then(console.log);

This returns results like this.

Result {
  '0': '2017-08-28',
  '1': '19:18:04.986593',
  '2': '07:17:00',
  '3': '11112323',
  '4': '12',
  date: '2017-08-28',
  login_time: '19:18:04.986593',
  logout_time: '07:17:00',
  login_device_id: '11112323',
  user_id: '12' }

Now when i want to console single tag through console.log(test[0]); this returns undefined My approach is to store every result tag in its individual variable. Need some suggestion.

Oct 9, 2018 in Blockchain by digger
• 26,740 points
459 views

1 answer to this question.

0 votes

then() takes a function as argument that is called on fulfillment of the promise. You can then add the value to an array for example:

var results = []
contract_instance.methods.getPost(15).call().then(function(value){
   console.log(value)
   results.push(value)
});

results[0] would then be the result object you are looking for and results[0]['0'] would give you the date '2017-08-28' for example.

answered Oct 9, 2018 by Omkar
• 69,220 points

Related Questions In Blockchain

0 votes
1 answer

Unable to change a state variable in a contract

I am assuming that the issue is ...READ MORE

answered Oct 30, 2018 in Blockchain by Christine
• 15,790 points
541 views
+1 vote
1 answer

Is it possible to store blockchain in a sql or no-sql database?

Currently, following are the options to store ...READ MORE

answered Apr 21, 2018 in Blockchain by Perry
• 17,100 points

edited Aug 9, 2018 by Omkar 1,138 views
0 votes
1 answer

How do I send back ethers to the sender of the tokens in a smart contract?

Whenever a smart contract receives ether via ...READ MORE

answered May 30, 2018 in Blockchain by Perry
• 17,100 points
3,608 views
0 votes
1 answer
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,927 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,455 views
+3 votes
2 answers

How to run ethereumjs using Node.JS

You need to install testrpc globally on ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,610 points
1,418 views
+1 vote
2 answers

Can I include real world data in a smart contract? If so, how?

You cant access/embed real world data using ...READ MORE

answered Jul 18, 2018 in Blockchain by sapan
1,165 views
0 votes
1 answer

Not able to invoke a contract in Ethereum Private chain using geth

Hope this helps: contract mortal { /* ...READ MORE

answered Oct 22, 2018 in Blockchain by Omkar
• 69,220 points
983 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP