我正在查看代码示例,如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);发布于 2016-10-11 18:10:48
我来自厄里斯。很抱歉我们的文件不够清楚。
编译稳固性的最简单方法是使用用于Solidity编译器的JavaScript绑定。
$ npm安装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
})发布于 2016-10-10 15:49:26
我从未使用eris,但如果您的问题是如何使用javascript编译该合同:
pragma solidity ^0.4.0;
contract test {
function multiply(uint a) returns(uint d) {
return a * 7;
}
}你试过浏览器-坚固性了吗?它会立即编译浏览器中的可靠代码。上述“稳固代码”的汇编合同是:
606060405260788060106000396000f360606040526000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa1146039576035565b6002565b34600257605160048080359060200190919050506067565b6040518082815260200191505060405180910390f35b60006007820290506073565b91905056和接口(ABI):
[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"payable":false,"type":"function"}]若要使用web3js部署它,请使用以下代码:
/* the test contract interface */
var testContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"payable":false,"type":"function"}]);
/* deploy it with web3, here: on ethereum */
var test = testContract.new(
{
from: web3.eth.accounts[0],
data: '606060405260788060106000396000f360606040526000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa1146039576035565b6002565b34600257605160048080359060200190919050506067565b6040518082815260200191505060405180910390f35b60006007820290506073565b91905056',
gas: 4700000
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})我不确定我是否回答了你自下而上的问题。如果问题是需要一个有效的JSON提供程序,您可以运行一个本地盖斯节点并指向RPC端口,默认情况下它是localhost:8545。
很抱歉,我不能按照eris的要求回答这个问题,但是如果您想要使用web3js进行可靠的编译,这应该是可行的。
发布于 2016-10-11 15:31:07
通过使用他们指定的编译器,我最终解决了eris链上的问题。但我似乎找不到像web3中提供的那样的js编译器。在ubuntu上安装eris-编译器
sudo apt-get install golang
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
go get github.com/eris-ltd/eris-compilers/cmd/eris-compilers
sudo add-apt-repository ppa:ethereum/ethereum
sudo add-apt-repository ppa:ethereum/ethereum-dev
sudo apt-get update
sudo apt-get install lllc sc solc
sudo apt-get install solc编译源代码
eris-compilers --debug compile -s -u compilers.monax.io -p 10120 idi.sol编译后的产品如下所示:
ngzhongqin@server2:/prodlib/ERIS/.eris/apps/idi-service$ eris-compilers --
debug compile -s -u compilers.monax.io -p 10120 idi.sol
Cached Item(s) cached?=false
Could not find cached object, compiling...
Response abi=[{"constant":true,"inputs":[],"name":"getName","outputs":[{"name":"retVal","type":"string"}],"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"string"}],"name":"setName","outputs":[],"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":false,"name":"_name","type":"string"}],"name":"SetName","type":"event"}]
bin=6060604052610399806100126000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806317d7de7c1461005a57806360fe47b1146100d55780636d4ce63c146100ed578063c47f00271461011057610058565b005b61006760048050506102dd565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156100c75780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6100eb6004808035906020019091905050610166565b005b6100fa6004805050610174565b6040518082815260200191505060405180910390f35b6101646004808035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050909091905050610186565b005b806000600050819055505b50565b60006000600050549050610183565b90565b8060016000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106101d557805160ff1916838001178555610206565b82800160010185558215610206579182015b828111156102055782518260005055916020019190600101906101e7565b5b5090506102319190610213565b8082111561022d5760008181506000905550600101610213565b5090565b50503373ffffffffffffffffffffffffffffffffffffffff167f5b55a57845097b0b4cf682f6d089fe6bad81dc28242927eca133f4b1c4d28b448260405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156102cc5780820380516001836020036101000a031916815260200191505b509250505060405180910390a25b50565b602060405190810160405280600081526020015060016000508054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561038a5780601f1061035f5761010080835404028352916020019161038a565b820191906000526020600020905b81548152906001019060200180831161036d57829003601f168201915b50505050509050610396565b9056
name=IdisContractsFTW
ngzhongqin@server2:/prodlib/ERIS/.eris/apps/idi-service$ https://stackoverflow.com/questions/39944282
复制相似问题