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(error);
console.log(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')
.