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:

(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
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}


Your issue is most likely caused by a missing from: eth.accounts[0] parameter from your eth.sendTransaction(...) call.

Try running either of the following step-by-step examples to see what kind of parameters and data is expected at each step:

If you can run either of the examples above, your geth and solc installation is working as expected, and your problem is most likely in the parameters of your eth.sendTransaction(...) call.

Answering question in the comment below

I would next check your data: code statement.

You should see the following type of result when you type code:

> code

If your data looks different, you are not passing your compiled code to the eth.sendTransaction(...) call.

Further edit - seeing that you are using JSON-RPC to deploy

There is some example code in https://github.com/ethereum/web3.js/blob/develop/example/contract.html to deploy a contract using JSON-RPC.

There is an assignment to the default account in the example:

web3.eth.defaultAccount = web3.eth.coinbase;

And the Application Binary Interface is passed using the eth.contract(...).new(...) call.

var abi = compiled.test.info.abiDefinition;
web3.eth.contract(abi).new({data: code}, function (err, contract) {

One other thing is to make sure that you account is unlocked, so you will have to run geth with parameters similar to

geth --rpc --unlock 0 console
Unlocking account 0 | Attempt 1/3
  • I have changed that line as "web3.eth.sendTransaction(_greeting,{from:web3.eth.accounts[0], data: bytecode, gas: 300000}, function(err, address){}". Still it is not working.@BokkyPooBah
    – Aniket
    Jul 15 '16 at 14:01
  • See addition to my answer Jul 15 '16 at 14:08
  • I chose different contract, added '0x' in bytecode and its working. But when i pass '_greeting' as a value for constructor, its not working
    – Aniket
    Jul 15 '16 at 14:24

As Bokky mentioned, you need a from key and sending address tuple when calling send transaction. Have a look at a valid transaction here (contract deployment transactions are very similar, see below):

web3.eth.sendTransaction({from: web3.eth.coinbase, to: '0x2910543af39aba0cd09dbb2d50200b3e800a63d2', value: web3.toWei(1, 'ether'), data: web3.toHex('EN7FQHHVG'), gas:25000});

A contract deployment transaction would look like:

var _greeting = "Hello World!"
var greeterContract = web3.eth.contract(greeterCompiled.greeter.info.abiDefinition);

var greeter = greeterContract.new(_greeting,{from:web3.eth.accounts[0], data: greeterCompiled.greeter.code, gas: 300000}, function(e, contract){
    if(!e) {

      if(!contract.address) {
        console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined...");

      } else {
        console.log("Contract mined! Address: " + contract.address);

  • I am also trying the same. I am trying to deploy it using web3 & JSON-RPC. And after adding the 'from' field, i am still having same error.
    – Aniket
    Jul 15 '16 at 14:05
  • Can you please edit your question to show all the field values you are passing to sendTransaction?
    – Sebi
    Jul 15 '16 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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