我知道如何通过"npm -保存solc“安装solc,然后使用solc.compile编译一个compile。但是现在我有了导入A.sol文件的B.sol文件,当我运行节点compile.js时,我的终端中没有错误,但是没有生成json文件!
但是,当我使用相同的compile.js来简化B.sol时,它就能工作了。为什么?如何在Solidity文件中修复此导入功能?谢谢。
发布于 2018-04-19 10:04:28
const pathA = path.resolve(__dirname, 'contracts', 'A.sol');
//to find the path of A.sol inside the folder 'contract' in your project
const pathB = path.resolve(__dirname, 'contracts', 'B.sol');
const solA = fs.readFileSync(pathA, 'utf8');
const solB = fs.readFileSync(pathB, 'utf8');
const input = {
sources: {
'A.sol': solA,
'B.sol': solB
}
};
console.log(solc.compile(input, 1));发布于 2021-01-24 06:30:15
添加它们作为源,是的,但是如果使用solcjs,也会添加一个导入回调。
https://github.com/ethereum/solc-js/issues/114#issuecomment-354752466
发布于 2022-01-31 02:27:28
我在浏览器上使用@remix-project/remix-solidity,它对我很有用。
只需打电话:
const response = await compile(
{
[CONTRACT_FILE_NAME]: {
content: source
}
}
, {
version: SOLIDITY_COMPILER_VERSION
}, handleNpmImport) as CompilerAbstract;源代码:https://github.com/vanduc1102/samples/blob/master/reactjs/cra-solidity-etherjs/package.json
https://ethereum.stackexchange.com/questions/46043
复制相似问题