我正在看如下所示的代码示例
https://github.com/eris-ltd/eris-contracts.js

var myAbi = [...];
var myCompiledCode = "...";

// Create a factory for the contract with the JSON interface 'myAbi'.
var myContractFactory = contractManager.newContractFactory(myAbi);

// To create a new instance and simultaneously deploy a contract use `new`:
var myNewContract;
myContractFactory.new({data: myCompiledCode}, function(error, contract){
     if (error) {
            // Something.
            throw error;
        }
     myNewContract = contract;
});


但是我不知道如何进行编译。
我了解eris-contracts.js建立在web3.js之上
但是我不确定在实例化web3对象时必须输入什么提供程序。

var edbFactory = require('eris-db');
var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://simplechain:1337/rpc'));

var edb = edbFactory.createInstance("http://simplechain:1337/rpc");

var source = "" +
    "contract test {\n" +
    "   function multiply(uint a) returns(uint d) {\n" +
    "       return a * 7;\n" +
    "   }\n" +
    "}\n";

var compiled = web3.eth.compile.solidity(source);
console.log(compiled);

最佳答案

我来自埃里斯(Eris)。抱歉,我们的文档尚不清楚。

编译Solidity的最简单方法是使用JavaScript bindings for the Solidity compiler

$ npm install solc-保存

const Solidity = require('solc')

var source = "" +
    "contract test {\n" +
    "   function multiply(uint a) returns(uint d) {\n" +
    "       return a * 7;\n" +
    "   }\n" +
    "}\n";

const compiled = Solidity.compile(source, 1).contracts.test
const abi = JSON.parse(compiled.interface)
const contractFactory = contractManager.newContractFactory(abi)

contractFactory.new({data: compiled.bytecode}, (error, contract) => {
  // use contract here
})

关于node.js - 如何使用eris的javascript编译一段Solidity代码?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39944282/

10-11 04:27