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.
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.
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.
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.
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.
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.
Blockchain app development can be confusing, using great tools can make it easier. These best practices (and more!) are built into DappStarter, our full-stack blockchain application generator.