1

I want to issue a contract with constructor parameters, without running a Geth node. Technically, I run a Geth node with a websocket proxy:

Light client (Node.js) <-- WebSocket --> Proxy (Node.js, web3.js) <-- HTTP --> Geth

I have simplified the code a bit, so it may not be runnable.

Client side code:

...
var Transaction = require('ethereumjs-tx');

// Helpers
var coder = require(path.join(__dirname, 'node_modules/web3/lib/solidity/coder'));

var encodeConstructorParams = function (abi, params) {
    return abi.filter(function (json) {
        return json.type === 'constructor' && json.inputs.length === params.length;
    }).map(function (json) {
        return json.inputs.map(function (input) {
            return input.type;
        });
    }).map(function (types) {
        return coder.encodeParams(types, params);
    })[0] || '';
};

// Private key
var privateKey = new Buffer("...", "hex");

// code, abi
var code = "60606040526001600...";
var abi = [ ... ];

var constructorParams = ["someString", "someString"];

var transaction = new Transaction();
transaction.nonce = 0;
transaction.gasPrice = 100;
transaction.gasLimit = 1000;
transaction.value = 0;
transaction.data = code

// Is this correct?
transaction.data += encodeConstructorParams(abi, constructorParams);

// Sign transaction
transaction.sign(privateKey);

var raw = transaction.serialize().toString('hex');

// (Send through websocket)

Server side code:

// (Receive hex-encoded transaction through websocket and call send rawTransaction)
web3.eth.sendRawTransaction(raw, function(err, hash) {
    if (err) {
        console.error("Error sending raw transaction");
        return ws.send(JSON.stringify({
            err: err,
            hash: hash
        }));
    }
    ...

This is the raw transaction:

raw = f90d4380648203e88080b90cf63630363036303430353236303031363030303630303035303535363030303630303436303030363130313030306138313534383136306666303231393136393038333032313739303535353036303430353136313035646233383033383036313035646238333339383130313630343035323830383035313930363032303031393039313930383035313832303139313930363032303031353035303562333336303031363030303631303130303061383135343831373366666666666666666666666666666666666666666666666666666666666666666666666666666666303231393136393038333032313739303535353038313630303236303030363130313030306138313534383137336666666666666666666666666666666666666666666666666666666666666666666666666666666630323139313639303833303231373930353535303830363030333630303035303930383035313930363032303031393038323830353436303031383136303031313631353631303130303032303331363630303239303034393036303030353236303230363030303230393036303166303136303230393030343831303139323832363031663130363130306633353738303531363066663139313638333830303131373835353536313031323435363562383238303031363030313031383535353832313536313031323435373931383230313562383238313131313536313031323335373832353138323630303035303535393136303230303139313930363030313031393036313031303535363562356235303930353036313031346639313930363130313331353635623830383231313135363130313462353736303030383138313530363030303930353535303630303130313631303133313536356235303930353635623530353034323630303536303030353038313930353535303562353035303631303436663830363130313663363030303339363030306633363036303630343035323336313536313030376635373630303033353763303130303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303930303438303633316233303132613331343631303038343537383036333164313433383438313436313031303435373830363333386166336565643134363130313432353738303633353466643464353031343631303138303537383036333633643235366365313436313031613835373830363336356232613836333134363130316432353738303633623830373737656131343631303232643537363130303766353635623631303030323536356233343631303030323537363130303936363030343830353035303631303235353536356236303430353138303830363032303031383238313033383235323833383138313531383135323630323030313931353038303531393036303230303139303830383338333832393036303030363030343630323038343630316630313034363030333032363030663031663135303930353039303831303139303630316631363830313536313030663635373830383230333830353136303031383336303230303336313031303030613033313931363831353236303230303139313530356235303932353035303530363034303531383039313033393066333562333436313030303235373631303131363630303438303530353036313032663635363562363034303531383038323733666666666666666666666666666666666666666666666666666666666666666666666666666666663136383135323630323030313931353035303630343035313830393130333930663335623334363130303032353736313031353436303034383035303530363130333163353635623630343035313830383237336666666666666666666666666666666666666666666666666666666666666666666666666666666631363831353236303230303139313530353036303430353138303931303339306633356233343631303030323537363130313932363030343830353035303631303334323536356236303430353138303832383135323630323030313931353035303630343035313830393130333930663335623334363130303032353736313031626136303034383035303530363130333462353635623630343035313830383231353135383135323630323030313931353035303630343035313830393130333930663335623334363130303032353736313032326236303034383038303335393036303230303139303832303138303335393036303230303139313931393038303830363031663031363032303830393130343032363032303031363034303531393038313031363034303532383039333932393139303831383135323630323030313833383338303832383433373832303139313530353035303530353035303930393039313930353035303631303335653536356230303562333436313030303235373631303233663630303438303530353036313034363635363562363034303531383038323831353236303230303139313530353036303430353138303931303339306633356236303033363030303530383035343630303138313630303131363135363130313030303230333136363030323930303438303630316630313630323038303931303430323630323030313630343035313930383130313630343035323830393239313930383138313532363032303031383238303534363030313831363030313136313536313031303030323033313636303032393030343830313536313032656535373830363031663130363130326333353736313031303038303833353430343032383335323931363032303031393136313032656535363562383230313931393036303030353236303230363030303230393035623831353438313532393036303031303139303630323030313830383331313631303264313537383239303033363031663136383230313931356235303530353035303530383135363562363030313630303039303534393036313031303030613930303437336666666666666666666666666666666666666666666666666666666666666666666666666666666631363831353635623630303236303030393035343930363130313030306139303034373366666666666666666666666666666666666666666666666666666666666666666666666666666666313638313536356236303030363030303530353438313536356236303034363030303930353439303631303130303061393030343630666631363831353635623630303136303030393035343930363130313030306139303034373366666666666666666666666666666666666666666666666666666666666666666666666666666666313637336666666666666666666666666666666666666666666666666666666666666666666666666666666631363333373366666666666666666666666666666666666666666666666666666666666666666666666666666666313631343135313536313033626135373631303030323536356236303031363030343630303036313031303030613831353438313630666630323139313639303833303231373930353535303766323636303935623561663765323332333736306665663135316631643738383936373430636432636331623733613633353766663965346333666461653734303831363034303531383038303630323030313832383130333832353238333831383135313831353236303230303139313530383035313930363032303031393038303833383338323930363030303630303436303230383436303166303130343630303330323630306630316631353039303530393038313031393036303166313638303135363130343535353738303832303338303531363030313833363032303033363130313030306130333139313638313532363032303031393135303562353039323530353035303630343035313830393130333930613135623530353635623630303536303030353035343831353630303030303030303030303030303030303030303030303033613531323237656661343434623433623131656565616431323331336665613537633264613565303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303034303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030343033343339333236363333363633333338363433363632333536343333363336313338333533393335333133343635333233353330363533323335363236313336333533393333333536323633363436343339363633343636333433303633333133323334363233373337333336363635333533333336363636353635333736341ca014704303807e160a04c800295dc8d460713aac08fe53c08f481cddb0573e6f7ea01bb6196dd08f2e8e8fb33f85091c2d630d6a926400fd4ebcb1847ea59495073e

Geth returns me an error message object in the callback, without keys: {}

2
  • Did you ever find out if (bytecode + encodeConstructorParams) for the transaction data is correct to deploy a new contract?
    – jjv360
    Aug 12, 2017 at 10:53
  • I think the issue was that I forgot to put "0x" in front of it
    – mitchkman
    Aug 12, 2017 at 20:11

0

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.