how to sign transaction during contract deployment

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I am looking at the web3js documentation to deploy a new contract, however, I see no mention of how to sign the transaction that will deploy the contract in the blockchain...document makes no mention of signing with private key...will appreciate any insight into this



here is the example code snippet from the docs (https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#eth-contract)



myContract.deploy(
data: '0x12345...',
arguments: [123, 'My String']
)
.send(
from: '0x1234567890123456789012345678901234567891',
gas: 1500000,
gasPrice: '30000000000000'
, function(error, transactionHash) ... )
.on('error', function(error) ... )
.on('transactionHash', function(transactionHash) ... )
.on('receipt', function(receipt)
console.log(receipt.contractAddress) // contains the new contract address
)
.on('confirmation', function(confirmationNumber, receipt) ... )
.then(function(newContractInstance)
console.log(newContractInstance.options.address) // instance with the new contract address
);







share|improve this question
























    up vote
    1
    down vote

    favorite












    I am looking at the web3js documentation to deploy a new contract, however, I see no mention of how to sign the transaction that will deploy the contract in the blockchain...document makes no mention of signing with private key...will appreciate any insight into this



    here is the example code snippet from the docs (https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#eth-contract)



    myContract.deploy(
    data: '0x12345...',
    arguments: [123, 'My String']
    )
    .send(
    from: '0x1234567890123456789012345678901234567891',
    gas: 1500000,
    gasPrice: '30000000000000'
    , function(error, transactionHash) ... )
    .on('error', function(error) ... )
    .on('transactionHash', function(transactionHash) ... )
    .on('receipt', function(receipt)
    console.log(receipt.contractAddress) // contains the new contract address
    )
    .on('confirmation', function(confirmationNumber, receipt) ... )
    .then(function(newContractInstance)
    console.log(newContractInstance.options.address) // instance with the new contract address
    );







    share|improve this question






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am looking at the web3js documentation to deploy a new contract, however, I see no mention of how to sign the transaction that will deploy the contract in the blockchain...document makes no mention of signing with private key...will appreciate any insight into this



      here is the example code snippet from the docs (https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#eth-contract)



      myContract.deploy(
      data: '0x12345...',
      arguments: [123, 'My String']
      )
      .send(
      from: '0x1234567890123456789012345678901234567891',
      gas: 1500000,
      gasPrice: '30000000000000'
      , function(error, transactionHash) ... )
      .on('error', function(error) ... )
      .on('transactionHash', function(transactionHash) ... )
      .on('receipt', function(receipt)
      console.log(receipt.contractAddress) // contains the new contract address
      )
      .on('confirmation', function(confirmationNumber, receipt) ... )
      .then(function(newContractInstance)
      console.log(newContractInstance.options.address) // instance with the new contract address
      );







      share|improve this question












      I am looking at the web3js documentation to deploy a new contract, however, I see no mention of how to sign the transaction that will deploy the contract in the blockchain...document makes no mention of signing with private key...will appreciate any insight into this



      here is the example code snippet from the docs (https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#eth-contract)



      myContract.deploy(
      data: '0x12345...',
      arguments: [123, 'My String']
      )
      .send(
      from: '0x1234567890123456789012345678901234567891',
      gas: 1500000,
      gasPrice: '30000000000000'
      , function(error, transactionHash) ... )
      .on('error', function(error) ... )
      .on('transactionHash', function(transactionHash) ... )
      .on('receipt', function(receipt)
      console.log(receipt.contractAddress) // contains the new contract address
      )
      .on('confirmation', function(confirmationNumber, receipt) ... )
      .then(function(newContractInstance)
      console.log(newContractInstance.options.address) // instance with the new contract address
      );









      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 3 at 5:55









      satyendra

      304




      304




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          3
          down vote













          enter image description here



          This is the method which can be used to sign transactions.






          share|improve this answer



























            up vote
            2
            down vote













            Try this (using web3.js v1):



            let fs = require("fs");
            let Web3 = require("web3");

            let web3 = new Web3(NODE_ADDRESS);

            async function send(transaction)
            let gas = await transaction.estimateGas(from: PUBLIC_KEY);
            let options =
            to : transaction._parent._address,
            data: transaction.encodeABI(),
            gas : gas
            ;
            let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
            return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);


            async function deploy(contractName, contractArgs)
            let abi = fs.readFileSync(contractName + ".abi").toString();
            let bin = fs.readFileSync(contractName + ".bin").toString();
            let contract = new web3.eth.Contract(JSON.parse(abi));
            let handle = await send(contract.deploy(data: "0x" + bin, arguments: contractArgs));
            console.log(`$contractName contract deployed at address $handle.contractAddress`);
            return new web3.eth.Contract(JSON.parse(abi), handle.contractAddress);


            async function run()
            let myContract = await deploy("MyContract", [123, "My String"]);
            ...






            share|improve this answer



























              up vote
              2
              down vote













              Using Web3.js 1.0.0



               var contractInstance = new web3.eth.Contract(contractABI);
              var deployData = contractInstance.deploy(
              data : contractByteCode
              ).encodeABI();

              var tx =
              data : deployData
              ;

              web3.eth.accounts.signTransaction(tx, privateKey).then (signed =>
              web3.eth.sendSignedTransaction(signed.rawTransaction).on('receipt', console.log)
              );



              signTransaction is the function you need to sign your transaction with the private key. For that you need to construct a transaction with the required data for the contract deployment i.e. contract abi and its byte code. Now, you can sign the trasaction and send it. You will get contract address of the newly deployed contract and other information in transaction receipt.






              share|improve this answer






















                Your Answer







                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "642"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                convertImagesToLinks: false,
                noModals: false,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                 

                draft saved


                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f57964%2fhow-to-sign-transaction-during-contract-deployment%23new-answer', 'question_page');

                );

                Post as a guest






























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                3
                down vote













                enter image description here



                This is the method which can be used to sign transactions.






                share|improve this answer
























                  up vote
                  3
                  down vote













                  enter image description here



                  This is the method which can be used to sign transactions.






                  share|improve this answer






















                    up vote
                    3
                    down vote










                    up vote
                    3
                    down vote









                    enter image description here



                    This is the method which can be used to sign transactions.






                    share|improve this answer












                    enter image description here



                    This is the method which can be used to sign transactions.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Sep 3 at 12:36









                    Puneet Kumar

                    47314




                    47314




















                        up vote
                        2
                        down vote













                        Try this (using web3.js v1):



                        let fs = require("fs");
                        let Web3 = require("web3");

                        let web3 = new Web3(NODE_ADDRESS);

                        async function send(transaction)
                        let gas = await transaction.estimateGas(from: PUBLIC_KEY);
                        let options =
                        to : transaction._parent._address,
                        data: transaction.encodeABI(),
                        gas : gas
                        ;
                        let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
                        return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);


                        async function deploy(contractName, contractArgs)
                        let abi = fs.readFileSync(contractName + ".abi").toString();
                        let bin = fs.readFileSync(contractName + ".bin").toString();
                        let contract = new web3.eth.Contract(JSON.parse(abi));
                        let handle = await send(contract.deploy(data: "0x" + bin, arguments: contractArgs));
                        console.log(`$contractName contract deployed at address $handle.contractAddress`);
                        return new web3.eth.Contract(JSON.parse(abi), handle.contractAddress);


                        async function run()
                        let myContract = await deploy("MyContract", [123, "My String"]);
                        ...






                        share|improve this answer
























                          up vote
                          2
                          down vote













                          Try this (using web3.js v1):



                          let fs = require("fs");
                          let Web3 = require("web3");

                          let web3 = new Web3(NODE_ADDRESS);

                          async function send(transaction)
                          let gas = await transaction.estimateGas(from: PUBLIC_KEY);
                          let options =
                          to : transaction._parent._address,
                          data: transaction.encodeABI(),
                          gas : gas
                          ;
                          let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
                          return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);


                          async function deploy(contractName, contractArgs)
                          let abi = fs.readFileSync(contractName + ".abi").toString();
                          let bin = fs.readFileSync(contractName + ".bin").toString();
                          let contract = new web3.eth.Contract(JSON.parse(abi));
                          let handle = await send(contract.deploy(data: "0x" + bin, arguments: contractArgs));
                          console.log(`$contractName contract deployed at address $handle.contractAddress`);
                          return new web3.eth.Contract(JSON.parse(abi), handle.contractAddress);


                          async function run()
                          let myContract = await deploy("MyContract", [123, "My String"]);
                          ...






                          share|improve this answer






















                            up vote
                            2
                            down vote










                            up vote
                            2
                            down vote









                            Try this (using web3.js v1):



                            let fs = require("fs");
                            let Web3 = require("web3");

                            let web3 = new Web3(NODE_ADDRESS);

                            async function send(transaction)
                            let gas = await transaction.estimateGas(from: PUBLIC_KEY);
                            let options =
                            to : transaction._parent._address,
                            data: transaction.encodeABI(),
                            gas : gas
                            ;
                            let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
                            return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);


                            async function deploy(contractName, contractArgs)
                            let abi = fs.readFileSync(contractName + ".abi").toString();
                            let bin = fs.readFileSync(contractName + ".bin").toString();
                            let contract = new web3.eth.Contract(JSON.parse(abi));
                            let handle = await send(contract.deploy(data: "0x" + bin, arguments: contractArgs));
                            console.log(`$contractName contract deployed at address $handle.contractAddress`);
                            return new web3.eth.Contract(JSON.parse(abi), handle.contractAddress);


                            async function run()
                            let myContract = await deploy("MyContract", [123, "My String"]);
                            ...






                            share|improve this answer












                            Try this (using web3.js v1):



                            let fs = require("fs");
                            let Web3 = require("web3");

                            let web3 = new Web3(NODE_ADDRESS);

                            async function send(transaction)
                            let gas = await transaction.estimateGas(from: PUBLIC_KEY);
                            let options =
                            to : transaction._parent._address,
                            data: transaction.encodeABI(),
                            gas : gas
                            ;
                            let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
                            return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);


                            async function deploy(contractName, contractArgs)
                            let abi = fs.readFileSync(contractName + ".abi").toString();
                            let bin = fs.readFileSync(contractName + ".bin").toString();
                            let contract = new web3.eth.Contract(JSON.parse(abi));
                            let handle = await send(contract.deploy(data: "0x" + bin, arguments: contractArgs));
                            console.log(`$contractName contract deployed at address $handle.contractAddress`);
                            return new web3.eth.Contract(JSON.parse(abi), handle.contractAddress);


                            async function run()
                            let myContract = await deploy("MyContract", [123, "My String"]);
                            ...







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Sep 3 at 7:03









                            goodvibration

                            1,754519




                            1,754519




















                                up vote
                                2
                                down vote













                                Using Web3.js 1.0.0



                                 var contractInstance = new web3.eth.Contract(contractABI);
                                var deployData = contractInstance.deploy(
                                data : contractByteCode
                                ).encodeABI();

                                var tx =
                                data : deployData
                                ;

                                web3.eth.accounts.signTransaction(tx, privateKey).then (signed =>
                                web3.eth.sendSignedTransaction(signed.rawTransaction).on('receipt', console.log)
                                );



                                signTransaction is the function you need to sign your transaction with the private key. For that you need to construct a transaction with the required data for the contract deployment i.e. contract abi and its byte code. Now, you can sign the trasaction and send it. You will get contract address of the newly deployed contract and other information in transaction receipt.






                                share|improve this answer


























                                  up vote
                                  2
                                  down vote













                                  Using Web3.js 1.0.0



                                   var contractInstance = new web3.eth.Contract(contractABI);
                                  var deployData = contractInstance.deploy(
                                  data : contractByteCode
                                  ).encodeABI();

                                  var tx =
                                  data : deployData
                                  ;

                                  web3.eth.accounts.signTransaction(tx, privateKey).then (signed =>
                                  web3.eth.sendSignedTransaction(signed.rawTransaction).on('receipt', console.log)
                                  );



                                  signTransaction is the function you need to sign your transaction with the private key. For that you need to construct a transaction with the required data for the contract deployment i.e. contract abi and its byte code. Now, you can sign the trasaction and send it. You will get contract address of the newly deployed contract and other information in transaction receipt.






                                  share|improve this answer
























                                    up vote
                                    2
                                    down vote










                                    up vote
                                    2
                                    down vote









                                    Using Web3.js 1.0.0



                                     var contractInstance = new web3.eth.Contract(contractABI);
                                    var deployData = contractInstance.deploy(
                                    data : contractByteCode
                                    ).encodeABI();

                                    var tx =
                                    data : deployData
                                    ;

                                    web3.eth.accounts.signTransaction(tx, privateKey).then (signed =>
                                    web3.eth.sendSignedTransaction(signed.rawTransaction).on('receipt', console.log)
                                    );



                                    signTransaction is the function you need to sign your transaction with the private key. For that you need to construct a transaction with the required data for the contract deployment i.e. contract abi and its byte code. Now, you can sign the trasaction and send it. You will get contract address of the newly deployed contract and other information in transaction receipt.






                                    share|improve this answer














                                    Using Web3.js 1.0.0



                                     var contractInstance = new web3.eth.Contract(contractABI);
                                    var deployData = contractInstance.deploy(
                                    data : contractByteCode
                                    ).encodeABI();

                                    var tx =
                                    data : deployData
                                    ;

                                    web3.eth.accounts.signTransaction(tx, privateKey).then (signed =>
                                    web3.eth.sendSignedTransaction(signed.rawTransaction).on('receipt', console.log)
                                    );



                                    signTransaction is the function you need to sign your transaction with the private key. For that you need to construct a transaction with the required data for the contract deployment i.e. contract abi and its byte code. Now, you can sign the trasaction and send it. You will get contract address of the newly deployed contract and other information in transaction receipt.







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Sep 3 at 7:57

























                                    answered Sep 3 at 6:54









                                    biplavo

                                    32117




                                    32117



























                                         

                                        draft saved


                                        draft discarded















































                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f57964%2fhow-to-sign-transaction-during-contract-deployment%23new-answer', 'question_page');

                                        );

                                        Post as a guest













































































                                        Comments

                                        Popular posts from this blog

                                        Long meetings (6-7 hours a day): Being “babysat” by supervisor

                                        Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                                        Confectionery