Solidity

導入錯誤:無法從布朗尼導入

  • August 6, 2022

如圖所示執行程式碼,我的建構子是公開的,但我不斷收到“無法從布朗尼導入彩票”作為錯誤。Lottery.sol 程式碼如下;

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.6;

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

contract lottery {
   address payable[] public players;
   uint256 public usdEntryFee;
   AggregatorV3Interface internal ethUsdPriceFeed;

   constructor(address _priceFeedAddress) public {
       usdEntryFee = 50 * (10**18);
       ethUsdPriceFeed = AggregatorV3Interface(_priceFeedAddress);
   }

   function enter() public payable {
       //$50 minimum
       players.push(msg.sender);
   }

   function getEntranceFee() public view returns (uint256) {
       //
       (, int256 price, , , ) = ethUsdPriceFeed.latestRoundData();
       uint256 adjustedPrice = uint256(price) * 10**10;
       uint256 costToEnter = (usdEntryFee * 10**18) / adjustedPrice;
       return costToEnter;
   }

   function startLottery() public {}

   function endLottery() public {}
}
`

The deploy.py code is below;
```#0.0317789204065159
#310000000000000000
from brownie import Lottery, accounts, config, network
from web3 import Web3


def test_get_entrance_fee():
   account = accounts[0]
   lottery = lottery.deploy(
       config["networks"][network.showactive()]["eth_usd_price_feed"],
       {"from": account},
   )
   assert lottery.getEntranceFee() > Web3.toWei(0.028, "ether")
   assert lottery.getEntranceFee() < Web3.toWei(0.038, "ether")```

lottry您已經用小寫字母寫了契約名稱。

要做的改變:

from brownie import Lottery, accounts, config, network

from brownie import 彩票 , accounts, config, network

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