Contract-Deployment

布朗尼:建構子序列的長度不正確,預期為 1 但得到了 0?

  • September 15, 2021

遵循本教程:https ://youtu.be/M576WGiDBdQ?t=18945 (為方便起見,加蓋時間戳!)

當我跑的時候brownie run scripts/deploy.py --network rinkeby我回來了

 File "brownie/_cli/run.py", line 49, in main
   return_value, frame = run(
 File "brownie/project/scripts.py", line 103, in run
   return_value = f_locals[method_name](*args, **kwargs)
 File "./scripts/deploy.py", line 12, in main
   deploy_fund_me()
 File "./scripts/deploy.py", line 7, in deploy_fund_me
   fund_me = FundMe.deploy({"from": account})
 File "brownie/network/contract.py", line 600, in __call__
   return tx["from"].deploy(
 File "brownie/network/account.py", line 507, in deploy
   data = contract.deploy.encode_input(*args)
 File "brownie/network/contract.py", line 629, in encode_input
   data = format_input(self.abi, args)
 File "brownie/convert/normalize.py", line 20, in format_input
   raise type(e)(f"{abi['name']} {e}") from None
ValueError: constructor Sequence has incorrect length, expected 1 but got 0

是指 ser 的嗎?

腳本/deploy.py:

from scripts.helpful_scripts import get_account


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


def main():
   deploy_fund_me()

腳本/helpful_scripts.py



def deploy_simple_storage():
   # account = accounts.add(config["wallets"]["from_key"])
   account = get_account()
   simple_storage = SimpleStorage.deploy({"from": account})
   stored_value = simple_storage.retrieve()
   print(stored_value)
   transaction = simple_storage.store(15, {"from": account})
   transaction.wait(1)
   updated_stored_value = simple_storage.retrieve()
   print(updated_stored_value)


def get_account():
   if network.show_active() == "development":
       return accounts[0]
   else:
       return accounts.add(config["wallets"]["from_key"])


def main():
   deploy_simple_storage()

嘗試使用這個可靠的程式碼:

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);
   }
}

引用自:https://ethereum.stackexchange.com/questions/109940