Trying call contract constructor with argument using Web3

vipulvipul Member Posts: 5
edited June 2015 in web3-js
Hi,

I am trying call the contract constructor with argument using Web3.


Solidity Contract Code
contract contractName {
	function contractName(address addr){
        address ConfigAddress = addr;
    }
}

Node Javascript Code:

var desc = [{"inputs":[{"name":"addr","type":"address"}],"type":"constructor"}]
var code = "602060266004396004805190602001505b60008190505b505060018060256000396000f30000";

/** Create Coupon Contract **/
app.get('/nameContarct', function(req, res) {
	web3.eth.defaultAccount = web3.eth.coinbase;
	Contract = web3.eth.contract(desc,"Passing argument");        
    var address = web3.eth.sendTransaction({from:"fromaddress",data: code,gas:500000});
    var myContract = Contract.at(address);
    console.log("Address : " + address);
    res.json(address);
});
I am pasing argument Like this in above code : Contract = web3.eth.contract(desc,"Passing argument");


Please give me suggestion.

Post edited by StephanTual on

Comments

  • PranayPranay Member Posts: 58
    I am getting the same problem, help appreciated.

    TIA
  • PranayPranay Member Posts: 58
    edited June 2015
    Hi Vipul,
    web3.eth.defaultAccount = web3.eth.coinbase;
    Contract = web3.eth.contract(desc);        
    var address = Contract.new(,{from:ADDRESS,data:DATA});
    Must work for argumented constructor. We do not the sendTransaction if we are doing new().

    Let me know if that works or not.

    (Thank you Fabian to help us in this. posting here for future reference)

    - Pranay
    Post edited by StephanTual on
  • vipulvipul Member Posts: 5
    Thanks Pranay .... :)
  • StephanTualStephanTual London, EnglandMember, Moderator Posts: 1,282 mod
    edited June 2015
    Guys there's a nice code formatting option if you look in the toolbar.

    If you could help me spread the word that would be great! Together we can fight unformatted code and make it a thing of the past! :)

    I've updated both your posts as an example.
Sign In or Register to comment.