2

I understood that print is not possible on Solidity, is recommended to use event and events can be read by using .watch. In order for an event to appear it has to be mined first.

What if I have a function in Solidity the goal is to search through an array and print out all elements that meet certain criteria. This constant function is to be executed locally, not via mining, is it possible?

  • Are you talking about a constant function? Is that what you mean by '...executed locally, not via mining..."? If yes, then maybe you can clarify the question by adding the words "This constant function..." If that's what you mean, and the data array is public, you should be able to do what you want, but you'll have to wait for a Javascript guru help you as I don't know how to do that in Javascript. – Thomas Jay Rush Aug 10 '17 at 11:02
  • @ThomasJayRush yes it is a constant function, and data array is public. Sorry for the confusion – Consy Aug 10 '17 at 14:23
  • This question could be improved by adding the (isolated) Solidity code that you are trying to make work. Perhaps you could insert a comment like // I want to print here, where you are stuck. – carver Aug 10 '17 at 17:28
1

Maybe what youre looking for, but I have code I use to loop through an array of addresses and then print out the addresses. This uses the web3 library and I use it from my node console. The first good thing about address arrays is that if its blank it just prints out 0x, so checking the length can tell me if somethings there.

var l = 4
var j = 0
while (l>3) {var x = ContractInstance.Array.call(j);
console.log(ContractInstance.Array.call(j)); j++;var l = x.length}
| improve this answer | |
  • Glad it works, thanks for the upvote and acceptance – thefett Aug 11 '17 at 13:09

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.