Smart Contracts, Gas and ICOs - Oh My

New Alchemy has just published the FunFair.io Token Creation contracts and the final Token contracts, and there are a number of things we did in them that I'm excited to talk about ahead of their June 22 launch.

N.b. This is a more technically minded blogpost; New Alchemy helps customers at all phases of their token project. if you have questions or need help, please drop us a line at [email protected].

Creation and Gas and Overstuffing

Gas costs are a big deal. For an ICO contract that requires 100k gas, only 30 or 40 contributions will be mined per block. Some miners don't mine transactions at all, so throughput during these times can be as as little 200 transactions per minute.

This is bad. Worse is that if the ICO contracts are not properly designed, they may have variable gas requirements depending on the contribution. Combined with laggy confirmations during an ICO, a large number of participants may try and contribute but offer too little gas, triggering a throw.

In most cases, they will then be forced to sit out the ICO.

Solutions: Constant, Low Gas

After the TokenCard launch New Alchemy had a goal that any future contribution contracts would have both low and constant gas costs.

We've got that done, and we're excited about it.

Constant Gas

Here's how an Ethereum wallet figures out how much gas to send: it calls the estimateGas function. estimateGas in most implementations is at best okay. In fact, many services rely on it not being perfect: the simplest way to tell if a transaction triggered a throw and failed is to test if it has zero gas left in it.

estimateGas can't look into the future, though, so for contracts where more contributions might change the gas required, many contributions don't offer enough gas. This sucks; the solution is to make sure that the gas estimator will be right at any point in the contract's future.

The contract we used for FunFair does a pretty good job at this; the very final transaction of the token sale changes state in a way that makes it cost a little more gas than the default, but that is probably the least objectionable time to have an out of gas error: it affects at most one participant who would otherwise have been able to participate.

We're excited to see how this plays out realtime and we think constant gas will make things smoother for participants.

Lower Gas

Gas costs for ICOs are high, between 60k and 200k. The FunFair Gas cost is just over 22,900. This is the lowest we know of for a contract that still manages start and stop times and enforces a hard cap.

The combination of lower and constant gas costs should make for easier participation and less drama on the day of the Token Launch--we're looking forward to seeing how it goes.

ERC20 Contributions

We think Token Creation events should take ERC20 tokens if they want to. The FunFair Contracts allow contributions from over 20 ERC20 tokens. This is awesome. We're pro ERC20, and like seeing them used this way.

More Cool Features Coming Soon

The FunFair Token contract has also been published and it includes our state of the art thoughts on what a solid, built-for-the-long-term token contract should do. Unlike some of the other popular tokens issued recently, we focus on upgradability in the logic layer. Look for more on our approach soon.

Peter Vessenes

Read more posts by this author.

Subscribe to Peter Vessenes

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!