1

I want to implement the callback function for simplicity's sake, so people can just send ether without calling a function.

However, I'm worried my callback function will require too much gas. It:

* records how much that address invested (in a mapping)
* adds address to an array
* increments a counter
* sends funds to collection wallet
* triggers an Event

1) I know the contract would run out of gas when getting called by another contract. Is it the same when someone manually sends ether from their account?

2) I've tested the fallback function on Rinkeby and it works fine. Is it safe to assume it'll work fine on the main net as well?

3) If not, what's a better way of collecting funds for an ICO?

4) Just to confirm: the fallback function is atomic right, so if the last operation runs out of gas, nothing writes and ether is not sent?

0

Every transaction sent has a "gas limit" value as part of it. Most Ethereum clients do estimations before generating the real transaction to guesstimate the amount of gas needed for that transaction. If your failback function does more logic, the Ethereum clients will be able to see that, and when a user "just sends ether" to your contract, that user's Ethereum client should suggest that the user send a higher gas limit with that transaction. So, unless the user ignores that suggestion and sets it back to a lower number, there should be no issues there.

If a transaction runs out of gas, the effects of the transaction are rolled back as if the transaction were never made (except the user who sent it loses the ether spent on gas. Any other ether attached to the transaction is returned though).

0

I've tested the fallback function on Rinkeby and it works fine. Is it safe to assume it'll work fine on the main net as well?

No, gas cost and gas limits can differ. Make sure you can deploy on the mainnet and test some token purchase there before ICO.

If not, what's a better way of collecting funds for an ICO?

Using the fallback is fine. Nobody will invoke a named transaction to buy tokens, it would be simply too complex for the average investor.

Just to confirm: the fallback function is atomic right, so if the last operation runs out of gas, nothing writes and ether is not sent?

All transactions are atomic by definition, it is all or nothing. If it runs out of gas the state of the chain is untouched. However, for a failed transaction the gas is lost, hence the sender can incur in some minor money loss.

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.