There are both synchronous and asynchronous versions of:
myContractInstance.myMethod.call(param1 [, param2, ...] [, transactionObject] [, defaultBlock] [, callback]);
as documented in https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-methods
Using the synchronous version:
var a = contract.getA.call();
numbers.push(a);
var b = contract.getB.call();
numbers.push(b);
b
will always be in the array after a
.
To use the asynchronous version, you pass a callback, like:
var a = contract.getA.call(function(error, value) {
});
The order of the array will depend on what's done in the callback/s.
Note that sendTransaction
should be used for setting the values and this won't work:
// Set the values
contract.call().setA(100);
contract.call().setB(200);
You need to use:
contract.setA.sendTransaction(100, callback);
and all the other code needs to be inside the callback
, because sendTransaction
is only asynchronous. Furthermore, the callback
of sendTransaction
will only return a transaction hash and you need to poll until getTransactionReceipt is not null
to know that the transaction has been mined and the value of a
has been set.
Best Answer
It would almost certainly be faster to parse the data directly from the
.ldb
files in thechaindata
directory, and then cache it. To do that would require you to parse it, which itself requires knowledge of how the data is stored.If you're using Node.js, you could take a look at "Exploring Ethereum's state trie with Node.js". (Node.js is probably not the best language to use for this.) Note that the code in the tutorial is slightly out of date. I've included a tweaked working version below.