There is a useful Solidity contract HERE. However, there are two things at time of its deployment:

(1) The first thing is the contract balance since its constructor is payable. (2) And the second one is the constructor's parameters value ((address **_recipient**, uint256 **duration**))

To deploy a contract I use web3.js 1.0.0-beta.34. Here is the steps I do to deploy this contract:

Web3 = require("web3")
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

const bytecode = '0x1234 ....
const abi = ....

web3.eth.personal.unlockAccount('0x123...', 'password')

var thisContract = new web3.eth.Contract(abi, {
    from: '0x123...',
    gasPrice: '20000000000'

thisContract.deploy({ data: bytecode }).estimateGas(function(err, gas) { console.log(gas); });

thisContract.deploy({ data: bytecode }).send({
        from: '0x123...',
        gas: 5000000 ,
        gasPrice: '3000000000'
    function(error, transactionHash) {
        console.log('function exec');
    }).then(function(newContractInstance) {
    console.log('Contract Instance:' + newContractInstance.options.address);

However, I do not know where in the above process I must determine (1) the contract balance (since its constructor is payable) and (2) the constructor's parameters value (i.e. (address _recipient, uint256 duration)) ?

Note: I guess first I have to deploy this contract using remix where I determine the constructor's parameters values and then use generated bytecode and abi by remix in the web3.js above code. However, I am not sure where can I use value: web3.toWei(1/*contract balance*/, 'ether').


Have a look at the example:

const thisContract = new web3.eth.Contract(abi);
        data: bytecode,
        arguments: [ "0x2345...", 12000 ] <- Here you put your constructor arguments in order
       from: "0x1234...",
       gas: 5000000 ,
       gasPrice: '3000000000',
       value: 120 <- Here you put how many wei to send to the constructor
    function(error, transactionHash) ...
  • Thank you very much for your answer. Just, I need to run JavaScript code to sign a payment by signPayment function (Full code is here). So, I saved the JavaScript code in a .js file (You can see the content of this .js file HERE.) However, when I run this file by node filename.js I receive the error message that I uploaded the screen shot HERE. I do not know where I am going wrong. Thanks again.
    – Questioner
    Jul 3 '18 at 11:08
  • You should probably open a full new question. Jul 3 '18 at 16:23
  • 1
    You have to replace callback with function(err, something) {}. Jul 3 '18 at 16:25
  • In fact, I asked another question here: ethereum.stackexchange.com/questions/52584/… Thanks.
    – Questioner
    Jul 3 '18 at 16:46
  • Thank you. I did your comment in the code and uploaded the new version. (now i receive Invalid JSON RPC response) I also added two important notes at the end of my question : web3.js version 1.0 and running this JavaScript file in Terminal (Ubuntu) : node filename.js Thanks again. ethereum.stackexchange.com/questions/52584/…
    – Questioner
    Jul 4 '18 at 8:48

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.