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
• 27,640 points
13 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
• 67,380 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 29, 2018 in Blockchain by Christine
• 15,790 points
24 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 20, 2018 in Blockchain by Perry
• 17,020 points

edited Aug 9, 2018 by Omkar 61 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,020 points
356 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
138 views
0 votes
1 answer
+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,620 points
136 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 17, 2018 in Blockchain by sapan
57 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
• 67,380 points
41 views