使用solcjs部署合同

时间:2016-11-04 22:40:47

标签: ethereum solidity

我正试图在教程博客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

1 个答案:

答案 0 :(得分:1)

此错误来自Solidity formal verification tool。到目前为止,它并不支持Solidity的大部分功能,因此您可以自由地忽略它们。

output.errors数组中返回实际编译错误。尝试添加一些拼写错误并运行:

const output = solc.compile({sources: input}, 1);
console.log(output.errors);