Creating contract account with ether balance in original sendTransaction?

by jojeyh   Last Updated November 09, 2018 01:28 AM

trying to send a very simple contract creation transaction that includes a value with it so that the created contract already contains an ether balance. Is this not possible. Basically I'm sending a transaction like this using the web3 console API,

web3.eth.sendTransaction({from:web3.eth.coinbase, data: <some contract data>, value: web3.toWei(1, 'ether')})

however I get a revert error.

I know that I can create the contract, and as long as the fallback function is payable in the contract I can then deposit ethers, but I'd like to be able to do this in one go when the contract is created. Is this possible?

In case it makes a difference I'm doing this in a truffle development chain console.

Tags : web3js truff


Answers 1


When deploying and sending value at the same time, your constructor needs to be "payable", otherwise it cannot receive value.

Micky Socaci
Micky Socaci
November 09, 2018 01:03 AM

Related Questions


How can I use web3 on the server

Updated June 25, 2017 22:28 PM


Trouble Installing web3 for node

Updated June 24, 2017 11:28 AM

New Coin Launch Announcement ICO recommended

Updated July 07, 2017 17:28 PM