My first own project

Hello Everyone,

Listening to Philip’s advise before I am moving on to the smart contract programming 201 course, I decided to create something on my own.

Here is what it looks like, not ready yet but I got an error which I don’t know how to solve.

So the main contract looks like this right now:

pragma solidity 0.7.5;

import "./BuildUp.sol";

    contract createSomething is BuildUp {

    
    event depositMade(address depositer, uint depositedAnEther);
    
    function deposit() public payable onlyOwners {
        balance[msg.sender] += msg.value;
        emit depositMade(msg.sender, msg.value);
        }
    function getBalance() public view returns(uint){
        return balance[msg.sender];
    }
    function transfer(address receiver, uint amount) public payable onlyOwners{
        balance[msg.sender] -= amount;
        balance[receiver] += amount;
    }
}

Then here is the inherited contract:

contract BuildUp{
    
    address public creator;
    address public owner;
    
    mapping (address => uint) balance;

  
    constructor(address _owner) {
        owner = _owner;
>     }
>     
>       modifier onlyOwners(){
>         require(msg.sender == owner || msg.sender == creator);
>         _;
>     }
> }

When I just would like to deploy it, I am getting the following error message: Contract createSomething should be marked as abstract.

Anyone can help me with it?

Thank you!

2 Likes

Hey @Riki, hope you are ok.

The error you mention is a suggestion from the console, your contract should work properly, the error appears when you have a contract without a constructor (abstracts contracts does not need a constructor), you can only have 1 constructor on the parent contract, then all child contracts became abstract waiting to be initialized by the parent contract.

Carlos Z

2 Likes

Maybe set the constructor to public? @thecil @Riki

Also, I would use some require statements for the transfer function like this:

function transfer(address receiver, uint amount) public payable onlyOwners{
        require(balance[msg.sender] >= amount, "Insufficient funds for this transaction!");
        balance[msg.sender] -= amount;
        balance[receiver] += amount;
    }

Also, this transfer function does not have to be payable, as you do not send any Ether to the contract, as for example in the deposit function. This transfer function is solely shifting balances inside the contract from one mapping key to the other. Is that correct?

2 Likes

Hey @Bhujanga

Good suggestions well done :slight_smile:

Edit: I did not notice the issue :joy: my bad. No need for the constructor to be set as public the issue is in the inheritance as @thecil suggested.
Still valid the require suggestion and the consideration for the function transfer that Bhujanga wrote.

2 Likes