2

我正在尝试按照该教程博客文章https://blog.topl.me/how-to-deploy-solidity/使用 solcjs 部署合同

这是我的代码

const web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545"));


async function compileAndDeploy() {
    let ambrosiaContract;
    try {
        let contract = await fs.readFileSync( path.join(__dirname, './Ambrosia.sol') );
        let Ambrosia = contract.toString();
        let input = {};
        input[ path.join(__dirname, './Ambrosia.sol')] = Ambrosia;

        console.log('> Compiling Storage');
        let output = solc.compile({sources: input}, 1);

        console.log(output.contracts, output.formal);
        ambrosiaContract = output.contracts['Ambrosia'];
    }
    catch (e) {
        console.log(e);
    }
    console.log('deploying...')
    let ambrosiaInstance = await deployStorage(ambrosiaContract)
    console.log('...deployed at ' + ambrosiaInstance.address)
}

compileAndDeploy();

现在,当我实际运行脚本时,编译器会将那个错误发回给我。

错误:状态变量不支持类型“bytes32”。\n 映射 (address => bytes32) 餐馆;\n

这是我的合同代码。

pragma solidity ^0.4.4;

contract Ambrosia {

    mapping (address => bytes32) restaurants;

    address _owner;

    event Transfer(address indexed _from, address indexed _to, uint256 _value); // listen to that event whenever a transfer has been made..

    event Order(address indexed _from, address indexed _to, uint256 _value); // listen to that event whenever an order is triggered

    function Ambrosia() {
        _owner = msg.sender;
    }
}

我正在使用 solcjs 版本 0.4.4 错误不依赖于节点客户端,它在开发网络上的 geth 和 js-eth 都发生

4

1 回答 1

1

此错误来自 Solidity形式验证工具。到目前为止,它不支持 Solidity 的大部分功能,因此您可以随意忽略它们。

实际编译错误以output.errors数组形式返回。尝试添加一些错字并运行:

const output = solc.compile({sources: input}, 1);
console.log(output.errors);
于 2017-01-11T06:53:05.873 回答