I am using the npm package of solc to compile the contracts and accessing it as given here. It is compiling my contracts. But when I try to deploy the contract using
web3.eth.sendTransaction({data: code}, function(err, address) {
if (!err)
console.log(address); // "0x7f9fade1c0d57a7af66ab4ead7c2eb7b11a91385"
});
as given here. I am doing all this in a JavaScript file. I am running a node locally using geth, and I am accessing it using the web3 httpprovider. When I execute the file, I am getting error as:
D:\Projectfolder\node_modules\solc\soljson.js:1
(function (exports, require, module, __filename, __dirname) { var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOve
rrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=typeof window==="object";var
ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_I
S_WEB&&!ENVIRONMENT_IS_WORKER;var ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){if(!M
odule["print"])Module["print"]=function print(x){process["stdout"].write(x+"\n")};if(!Module["printErr"])Module["printErr"]=function printErr(x){proce
ss["stderr"].write(x+"\n")};var nodeFS=require("fs");var nodePath=require("path");Module["read"]=function read(filename,binary){filename=nodePath["nor
malize"](filename);var ret=nodeFS["readFileSync"](filename);if(!
Error: invalid address
at inputAddressFormatter (D:\Projectfolder\node_modules\web3\lib\web3\formatters.js:271:11)
at inputTransactionFormatter (D:\Projectfolder\node_modules\web3\lib\web3\formatters.js:97:20)
at D:\Projectfolder\node_modules\web3\lib\web3\method.js:89:28
at Array.map (native)
at Method.formatInput (D:\Projectfolder\node_modules\web3\lib\web3\method.js:88:32)
at Method.toPayload (D:\Projectfolder\node_modules\web3\lib\web3\method.js:114:23)
at Eth.send [as sendTransaction] (D:\Projectfolder\node_modules\web3\lib\web3\method.js:139:30)
at Object.<anonymous> (D:\FILEPATH\check.js:22:10)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
How do I remove the error?
I tried another contract, changed the line as web3.eth.sendTransaction({from:web3.eth.accounts[0], data: bytecode, gas: 300000}
And it's working. But when I try to deploy famous greeter contract using web3 line as: web3.eth.sendTransaction(_greeting,{from:web3.eth.accounts[0], data: bytecode, gas: 300000}
It still throws error.
Oh, finally this is resolved. I just needed to add JSON.parse(abiDefinition). Now the greeter contract is also working. This one is deployed using greeterContract.new(_greeting,{from:web3.eth.accounts[0], data:bytecode, gas: 300000}