2

I am trying to deploy a contract on Rinkeby by running brownie run scripts/deploy.py --network rinkeby but I get following error:

Constructor Sequence has incorrect length, expected 1 but got 0

I think the problem is that I do NOT specify the initial value of the constructor when I run my deploy.py script. Is it correct? If yes, how can I fix it?

deploy.py

from brownie import FundMe
from scripts.helpful_script import get_account


def deploy_fund_me():
    account = get_account()
    fund_me = FundMe.deploy({"from": account})
    print(f"Contract deployed to {fund_me.account}")

Solidity contract

pragma solidity ^0.6.6;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol";

contract FundMe {
    using SafeMathChainlink for uint256;

    mapping(address => uint256) public addressToAmountFunded;
    address[] public funders;
    address public owner;
    AggregatorV3Interface public priceFeed;

    constructor(address _priceFeed) public {
        priceFeed = AggregatorV3Interface(_priceFeed);
        owner = msg.sender;
    }
    ...OTHER FUNCTIONS...
    }
}

2 Answers 2

3

Constructor Sequence has incorrect length means the number of parameters you're passing to the deploy function is off.

Your constructor is defined as:

constructor(address _priceFeed) public {

However, you don't pass it any parameters when you deploy it:

fund_me = FundMe.deploy({"from": account})

(the {"from": account} doesn't count as a constructor parameter)

So you could either:

  1. Change the constructor
constructor() public {
        owner = msg.sender;
    }

Keep in mind, this means that you're not use the pricefeed anywhere. You can see a version of the refactored code here.

  1. Change the deploy script
def deploy_fund_me():
    account = get_account()
    fund_me = FundMe.deploy( <PRICE_FEED_ADDRESS_HERE>, {"from": account})
    print(f"Contract deployed to {fund_me.account}")

You can see a refactored version of that here.

0

This can be a solution:

https://github.com/PatrickAlphaC/brownie_fund_me/issues/1

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.6;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol";

contract FundMe {
    using SafeMathChainlink for uint256;

    mapping(address => uint256) public addressToAmountFunded;
    address[] public funders;
    address public owner;

    constructor() public {
        owner = msg.sender;
    }

    function fund() public payable {
        uint256 mimimumUSD = 50 * 10**18;
        require(
            getConversionRate(msg.value) >= mimimumUSD,
            "You need to spend more ETH!"
        );
        addressToAmountFunded[msg.sender] += msg.value;
        funders.push(msg.sender);
    }

    function getVersion() public view returns (uint256) {
        AggregatorV3Interface priceFeed = AggregatorV3Interface(
            0x8A753747A1Fa494EC906cE90E9f37563A8AF630e
        );
        return priceFeed.version();
    }

    function getPrice() public view returns (uint256) {
        AggregatorV3Interface priceFeed = AggregatorV3Interface(
            0x8A753747A1Fa494EC906cE90E9f37563A8AF630e
        );
        (, int256 answer, , , ) = priceFeed.latestRoundData();
        return uint256(answer * 10000000000);
    }

    // 1000000000
    function getConversionRate(uint256 ethAmount)
        public
        view
        returns (uint256)
    {
        uint256 ethPrice = getPrice();
        uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;
        return ethAmountInUsd;
    }

    modifier onlyOwner() {
        require(msg.sender == owner);
        _;
    }

    function withdraw() public payable onlyOwner {
        msg.sender.transfer(address(this).balance);

        for (
            uint256 funderIndex = 0;
            funderIndex < funders.length;
            funderIndex++
        ) {
            address funder = funders[funderIndex];
            addressToAmountFunded[funder] = 0;
        }
        funders = new address[](0);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.