I am using truffle (javascript) to test my solidity contracts and want to automatically run my contract functions a large number of times. I can't figure out how to make a for loop work with promises however as I need it to wait until the whole loop is finished to start again. I'm currently just using a regular for loop with the promises chained up within it. I have included below my roughly anonymised code.


for(var j = 0; j < 5; j++) {
    //create parameters for function
    runFunc(param1 ,param2);

function runFunc(param1, param2) {
    contract.func1.call(param1).then(function(return1) {
        var var1 = = web3.toAscii(account1hash.valueOf());
        contract.func2(param2, var1).then(function() {
            contract.func3(param1, param2);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.