Abstract Contracts In Solidity TypeError: No arguments passed to the base constructor. Specify the arguments or mark "AssetAcquisition" as abstract
Asked Answered
H

3

6

I had an issue with a solidity contract in which the error demanded I write my code as an abstract. Abstract means my code will be non-deployable.

This is a contract that aims to transfer assets and acquisition. Just random stuff!

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
import './StringUtils.sol';

// @dev contract for rock,paper game0
contract AssetAcquisition is Ownable, ERC20 {
    string private _tokenname = "MATTokens";
    string private _tokensymbol = "MAT";
    address public _owner;
    uint randNonce = 0;
    uint modulus = 0;
    uint maxWaitTime = 100;

    struct Assets {
        address owner;
        address sender;
        address payable receiver;
        uint256 amountleft;
        uint256 datesent;
    }

    uint256 public _totalSupply = 1000000;
    mapping(address => uint256) balances;
    mapping(address => mapping(address => uint256)) private _allowances;
    mapping(address => Assets) public assetstore;
    Assets newasset;
    Assets[] public assetstorage;

    event AssetTransferAndMergerEvent(address payable _companyaddress, address payable _mergeraddress, uint256 amount);
    event AssetTransferMergerDetails(address owner, address sender, address payable receiver, uint256 amountleft, uint256 datesent);

    constructor(address __owner, string memory _tokenName, string memory _tokenSymbol) ERC20(_tokenName, _tokenSymbol) {
        _owner = __owner;
    }

 
} ```
   
Holocaine answered 31/5, 2023 at 8:23 Comment(0)
H
4

I replaced the constructor with this since it is expecting initial address.

constructor(address initialOwner) Ownable(initialOwner) ERC20(_tokenname, _tokensymbol) {
_owner = initialOwner;

}

Also for inheriting contracts this was the procedure

constructor(address _themergeraddress, address _initialOwner) AssetAcquisition(_initialOwner) {
themergeraddress = _themergeraddress;

}

Holocaine answered 31/5, 2023 at 8:23 Comment(0)
J
4

In my case, I had issue with Ownable contract. Adding this constructor solved my issue. Though before I didnt need to initiate Ownable in constructor. I think it can be related to pragma version or blockchain itself.

   constructor() Ownable(msg.sender) {

    }
Jordaens answered 20/1 at 9:52 Comment(2)
Update 2024: If you encounter this error when you run Remix on Google Chrome, try Microsoft EdgeJordaens
passoing msg.sender also worked for my case.Quaver
S
1

In Solidity, a Contract can inherit from another contract using the is keyword. In this case, the derived contract needs to specify the arguments for the base contract one of two ways:

contract Base {
    uint x;
    constructor(uint x_) { x = x_; }
}

// Either directly specify in the inheritance list...
contract Derived1 is Base(7) {
    constructor() {}
}

// or through a "modifier" of the derived constructor...
contract Derived2 is Base {
    constructor(uint y) Base(y * y) {}
}

Example

Sit answered 21/11, 2023 at 4:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.