* Rename Base Camp to Base Learn * Rename Base Camp to Base Learn * Update learn link * change wallet type property from camel to snake case (#643) * Update api key requirement, minor style updates (#642) * Fix type and clarify inheritance ex (#655) * Document Reth snapshot URLs (#651) * feat(ecosystem): New additions to Ecosystem page (#647) * feat(ecosystem): New additions to Ecosystem page * chore(Ecosystem): Add image for Dynamic * Update preparing-for-fault-proofs-on-base-sepolia.md (#633) Update preparing-for-fault-proofs-on-base-sepolia * Fix conflict * fix conflict --------- Co-authored-by: Brendan from DeFi <brendan.forster@coinbase.com> Co-authored-by: Danyal Prout <danyal.prout@coinbase.com> Co-authored-by: wbnns <hello@wbnns.com> Co-authored-by: Olexandr Radovenchyk <radole1203@gmail.com>
1.7 KiB
title, description, hide_table_of_contents
| title | description | hide_table_of_contents |
|---|---|---|
| Basic Functions Exercise | Exercise - Create and deploy a contract with simple math functions. | false |
Each module in this course will contain exercises in which you are given a specification for a contract without being given specific instructions on how to build the contract. You must use what you've learned to figure out the best solution on your own!
:::info
Once you've learned how to deploy your contracts to a test network, you'll be given the opportunity to submit your contract address for review by an onchain unit test. If it passes, you'll receive an NFT pin recognizing your accomplishment.
You'll deploy and submit this contract in the next module.
:::
The following exercise asks you to create a contract that adheres to the following stated specifications.
Contract
Create a contract called BasicMath. It should not inherit from any other contracts and does not need a constructor. It should have the following two functions:
Adder
A function called adder. It must:
- Accept two
uintarguments, called_aand_b - Return a
uintsumand aboolerror - If
_a+_bdo not overflow, it should return thesumand anerroroffalse - If
_a+_boverflow, it should return0as thesum, and anerroroftrue
Subtractor
A function called subtractor. It must:
- Accept two
uintarguments, called_aand_b - Return a
uintdifferenceand aboolerror - If
_a-_bdoes not underflow, it should return thedifferenceand anerroroffalse - If
_a-_bunderflows, it should return0as thedifference, and anerroroftrue