Creating contract account with ether balance in original sendTransaction?

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

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 to get private key with web3 v0.2.x?

Updated January 06, 2019 18:28 PM

Cannot deploy contract

Updated March 25, 2019 23:28 PM