1

I have a smart contract where user can transfer ETH to an ICO. Like this

function buyICO(paymentAddress, amount) {

// do some other important things

// transfer the amount to the payment address
paymentAddress.transfer(amount);

}

Because some ICOs require a specific gas price and limit, but I can't set these in the transfer function. I can set it when user call buyICO() function but I don't know how do I calculate the gas limit and price for the whole thing.

What's the best practice here?

1

If you want to adjust gas limit you should use address.call.value().gas()(). See this answer for more details <address>.send vs <address>.transfer best practice usage? You can't adjust the gas price though.

  • sweeet, thanks for this! exactly what I needed. however would this be a problem that I can't adjust gas price? it is often required by ICOs to set a certain price and limit when participating. – Panda Power May 16 '18 at 10:03
  • Then you will have to set the gas price when calling buyICO() in the top level transaction. The internal call .transfer() inherits this price. – medvedev1088 May 16 '18 at 10:23
  • You can accept the answer if it helped – medvedev1088 May 16 '18 at 11:37

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.