Challenge: Create a Contract with Attributes and Functions
Test yourself on Solidity by creating contracts with different parameters and coding the respective run scripts.
We'll cover the following
Problem statement
Create a contract named Challenge
with the following attributes and functions:
A
private
variable calledtargetAmount
, which is equal to2
.The
constructor
function that should accept an argument calledamount
.The
constructor
should check if theamount
is equal to thetargetAmount
. If not, it should fail with the error messageError
.
Write a main
function for a Hardhat run
script that would load the Challenge
contract you created earlier and deploy with the Hardhat generated address.
Input
There is no input for this challenge.
Output
The code will display the error message.
Try it yourself
Write the code for the contract in the contracts/contract.sol
file and the run
script in the scripts/run.js
file. Click the “Run” button in the code widget below to test your solution:
Get hands-on with 1400+ tech skills courses.