I'm new to Nodejs and Ethereum so I apologize in advance for any obvious mistakes.

I want to deploy multiple contracts in advance to have addresses ready when they are needed.

I use this to deploy the contract:

    data: contractCode,

    from: ownerAddress,
    gas: 4000000,
    gasPrice: gasPrice,
}, function (error, transactionHash) {

    if(error) console.log(error);



which works fine so far if I only deploy one contract. If I try to deploy multiple ones with a for loop I get the error:

Error: Returned error: known transaction:

Does anyone know how to solve this?

Thanks in advance


In case anyone ever stumbles upon this problem this is the solution: the nonce has to be increased for every deployed contract

.then(nonce => {

    web3.eth.personal.unlockAccount(senderAddress, password)
        .then(() => {

        for (let i = 0; i < amountOfContractsToBeSendOut; i++) {; 

            let contract = new web3.eth.Contract(contractABI);

                data: contractByteCode
                    from: senderAddress,
                    gas: (500000),
                    gasPrice: 5000000000,
                    nonce: nonce
                }, function (error, transactionHash) {

                    if(error) {


                .on('transactionHash', (transactionHash) => console.log(transactionHash))
                .on('receipt',  (receipt) => {

                .on('error', error => console.error(error))

            nonce++; //important!



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.