DEV Community

Cover image for Best practices to avoid costly or irreversible mistakes in blockchain app development
Mai Luong
Mai Luong

Posted on • Updated on • Originally published at trycrypto.com

Best practices to avoid costly or irreversible mistakes in blockchain app development

Blockchain app development can be tricky. We've put together 5 tips and best practices to avoid costly or irreversible mistakes when it comes to blockchain development.

Alt Text

1. Item Collections

Do: Have the client call the smart contract function for each item

Don't: Loop through each item in your smart contract function

Every line of code executed on a smart contract costs money! To save money and improve efficiency, have the client call the smart contract function for each item, rather than looping through each item in your smart contract.

Alt Text

2. Transferring Funds

Do: Have the user "pull" funds

Don't: Send funds to the user by using "push"

Transferring funds can be a high-stakes process. Having the user pull funds, rather than pushing funds to the user can avoid mistakes and immutable errors.

Alt Text

3. Reducing Gas Fees

Do: Validate all inputs before using them in code

Don't: Intersperse input validation within code

Again, smart contract execution is costly. Be sure to validate all inputs before using them in code to avoid expensive errors before it's too late.

Alt Text

4. Arithmetic Errors

Do: Use a library that checks for numeric overflow/underflow

Don't: Perform arithmetic in smart contracts without bounds-checking

Arithmetic errors are never good, but in smart contracts ‒ they're irreversible. Use a library that checks for numeric overflow/underflow to ensure arithmetic errors don't become an expensive headache.

Alt Text

5. Minimizing On-chain Data

Do: Hash data on-chain and store actual values off-chain

Don't: Store large amounts of data on-chain

Storing data on-chain is incredibly expensive. Using a decentralized storage solution such as IPFS or Sia is a best-practice to maintain the decentralized nature of an app without racking up cost.

6. (Extra tip!) Using Great Tools

Blockchain app development can be confusing, using great tools can make it easier. These best practices (and more!) are built into DappStarter, Decentology's full-stack blockchain application generator.

More best practices for blockchain app development (3 part series):

Top comments (0)