How do I compile a piece of Solidity Code using eris javascript

0 votes

I'm looking at the code example as shown in 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;
});

But I've no idea how to do the compilation. I understand that the eris-contracts.js is built on web3.js But I'm not sure what the provider I've got to enter when instantiating web3 object.

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);
Sep 27, 2018 in Blockchain by slayer
• 29,350 points
636 views

1 answer to this question.

0 votes

The easiest way to compile Solidity is to use the JavaScript bindings for the Solidity compiler.

$ npm install solc --save

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
})
answered Sep 27, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer

How do I send back ethers to the sender of the tokens in a smart contract?

Whenever a smart contract receives ether via ...READ MORE

answered May 30, 2018 in Blockchain by Perry
• 17,100 points
3,366 views
0 votes
1 answer

How do i deploy a contract using bigchainDB?

Currently BigchainDB v.1.0.0 does not support Smart ...READ MORE

answered Jun 30, 2018 in Blockchain by Shashank
• 10,400 points
896 views
+1 vote
1 answer
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,691 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,232 views
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 69,210 points
1,247 views
0 votes
1 answer

Solidity: How can I return a list of user-defined function?

You can do it with something like ...READ MORE

answered Sep 26, 2018 in Blockchain by digger
• 26,740 points
1,135 views
0 votes
1 answer

How to get all address and send ethers in solidity using a loop?

I found a similar code somewhere: contract  Holders{ uint ...READ MORE

answered Jul 31, 2018 in Blockchain by digger
• 26,740 points
2,551 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP