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?
from:
field in the tx object in thenew
call. Just putfrom:eth.coinbase
before the data field.