0

By using the Truffle Console and Ganache test node, I am calling this function:

Contract.deployed().then(function(instance) {return instance.createListing("1", 3, {from: address})})

When this will be deployed to the Mainnet, I will need to call this function 200 times. Figured, that a for loop should be used, however, can't understand how to get together one and how to run it on the Mainnet (geth?).

What would be the best way of repeating this setter 200 times on the Mainnet? Also, I guess a delay in between the calls needs to be considered when on Mainnet.

Ruham
  • 963
  • 2
  • 12
  • 34

1 Answers1

1

Just wrap the whole thing in a loop in a script and use the exec function.

So the file would look something like this:

    const Contract = artifacts.require('./MyContract.sol');



    module.exports =async function(callback) {
      let instance = await Contract.deployed();


      for(i = 0; i <=200; i++){
         await instance.createListing("1", 3, {from: address})
      }
}

and then just call it from your truffle console:

truffle exec thisscript.js --network mainnet

But gas and time will probably be considerable. If you own the contract, you might want to add a function for mass listing (like passing in an array)

Ruham
  • 963
  • 2
  • 12
  • 34
thefett
  • 3,873
  • 5
  • 26
  • 48
  • Thank you so much for the answer. Could you please elaborate more on the mass listing part? – Ruham Mar 29 '18 at 23:13
  • 1
    Glad it works...but here's a link to someone hitting the gas limit using the mass input: https://ethereum.stackexchange.com/questions/43247/trying-to-input-big-array-500-of-addresses-as-argument . But the code should work well and you would just input an array of uints that represent your variables – thefett Mar 30 '18 at 02:54
  • But I can't understand, if I run a single function and it costs 100k gas on Ganache, wouldn't it cost the same on the mainnet? And the daily limit there is 3M? – Ruham Mar 30 '18 at 03:28
  • I managed to run everything on Ganache and Ropsten, but on Mainnet it's failing after 2-3 iterations with "Nonce too low" error. Do you know a way to avoid this? – Ruham Mar 31 '18 at 03:28