首页 > 解决方案 > 指定的输入源无效

问题描述

使用 remix IDE 构建智能合约时,通过以下导入获取 Invalid input source specified 错误

import "https://github.com/aave/flashloan-box/blob/Remix/contracts/aave/FlashLoanReceiverBase.sol"; 

将一个超级基本的示例智能合约放在 remix 中。如果我不包含 import 语句,它编译得很好。

pragma solidity ^0.6.6;
import "https://github.com/aave/flashloan-box/blob/Remix/contracts/aave/FlashLoanReceiverBase.sol";
contract Inbox {
    string public message; 
    
    constructor(string memory initialMessage) public {
        message = initialMessage;
    }
    
    function setMessage(string memory newMessage) public {
        message = newMessage;
    }
    
    function getMessage() public view returns (string memory) {
        return message;
    }
}

标签: solidityremix

解决方案


发生此问题是因为使用相对路径的嵌套导入。

FlashLoanReceiverBase.sol正在尝试导入相对路径(./IFlashLoanReceiver.sol不是绝对路径https://github.com/aave/flashloan-box/blob/Remix/contracts/aave/IFlashLoanReceiver.sol)。

由于您没有IFlashLoanReceiver.sol与您自己的合同在同一文件夹中命名的合同,因此此导入失败。

最好的解决方案是将 PR 提交到aave/flashloan-box存储库,使所有导入路径都是绝对的。


推荐阅读