3

I am trying to deploy new contract on the net and I get two errors depending how exactly how I do it. Since I can not get ABI compiling contract on Parity I use solc --abi to get it. Now depending if I use compiled code or compile it on Parity I get one of two following errors:

..node_modules/web3/lib/web3/formatters.js:271
throw new Error('invalid address');

Error: invalid address - (when compiling contract with web3 on Parity)

or

Error: Invalid params - (when using contract compiled with solc)

Any ideas what I am doing wrong? Here is the code:

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

web3.eth.defaultAccount=web3.eth.accounts[0]

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);

var compiled = 0x606060405260788060106000396000f360606040526000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa1146039576035565b6002565b34600257605160048080359060200190919050506067565b6040518082815260200191505060405180910390f35b60006007820290506073565b91905056;

console.log(compiled);

var abi = [{"constant":true,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"payable":false,"type":"function"}]

web3.eth.contract(abi).new({data: compiled}, function (err, contract) {
    if(err) {
        console.error(err);
        return;
        // callback fires twice, we only want the second call when the contract is deployed
    } else if(contract.address){
        var myContract = contract;
        console.log('address: ' + myContract.address);
    }
});

It is worth noting that calling:

web3.eth.compile.solidity(source);

gives:

0x606060405260308060106000396000f3606060405260e060020a6000350463c6888fa18114601c575b6002565b346002576007600435026060908152602090f3

while solc --bin gives:

0x606060405260788060106000396000f360606040526000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa1146039576035565b6002565b34600257605160048080359060200190919050506067565b6040518082815260200191505060405180910390f35b60006007820290506073565b91905056

Shouldn't they give same outcome?

5
  • You don't need the newlines in the source. Its actually better to leave them out Sep 29, 2016 at 13:36
  • Also, the issue is that you need quotes around the bytecode. i.e. var compiled = "0x6060....." Sep 29, 2016 at 13:38
  • @TjadenHess tried both and now I get Error: invalid address in both cases. Thrown at formatters.js
    – wonglik
    Sep 29, 2016 at 14:52
  • Oh, that's because you need a from: field in the tx object in the new call. Just put from:eth.coinbase before the data field. Sep 29, 2016 at 15:06
  • @TjadenHess added from:web3.eth.accounts[0] and still same same issue .
    – wonglik
    Sep 29, 2016 at 15:24

1 Answer 1

0

There was a bug in Parity 1.3.0. After updating to 1.3.2 it is working fine.

More details here

1
  • issue still on 2.1.1
    – Dr.X
    Oct 29, 2018 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.