Smart contract best practices

Here are some general best practices that you should follow when developing smart contracts with Plutus.

Knowing the objective of your smart contract

Know exactly what your smart contract should do and test it to ensure that it fulfills the expected objective.

Check if previous, similar contracts exist

Does a contract that does the same thing already exist? If so, what is different about your smart contract?

Naming

Choose a clear and meaningful name for your smart contract. Keep it short and simple, and try to use the name to convey what the contract does.

Peer review of code

The benefits of code review are well known; reviewed code leads to consistency across the project, defect-free, and code optimized for performance. The knowledge of the code is shared among developers, reducing maintenance time and cost in the future. For smart contracts, correctness is absolutely crucial.

Testing on a testnet

You should always test your smart contracts on a testnet environment before running them on the mainnet. Write as many test scenarios as you can and run several iterations of your tests.

Documenting test cases

Keep a list of the test cases that you run so that you have them for reference and verification purposes.

Consider Formal Verification

The subject of formal verification is too large to adequately cover here. You can assume that your code will run in a hostile environment where highly skilled, well-resourced, and unscrupulous actors will be waiting to pounce on any vulnerability.

© IOHK 2015 - 2021


Cardano Logo

Cardano is an open-source project.

Cardano is a software platform ONLY and does not conduct any independent diligence on, or substantive review of, any blockchain asset, digital currency, cryptocurrency or associated funds. You are fully and solely responsible for evaluating your investments, for determining whether you will exchange blockchain assets based on your own judgement, and for all your decisions as to whether to exchange blockchain assets with Cardano. In many cases, blockchain assets you exchange on the basis of your research may not increase in value, and may decrease in value. Similarly, blockchain assets you exchange on the basis of your research may fall or rise in value after your exchange.

Past performance is not indicative of future results. Any investment in blockchain assets involves the risk of loss of part or all of your investment. The value of the blockchain assets you exchange is subject to market and other investment risks