I have a contract like the following:

contract HoneyPot {

  mapping (address => uint) public balances;

  function HoneyPot() payable {
    balances[msg.sender] = msg.value;


When deploying the contract I want to send some ether so the balances[msg.sender] for the account deploying the contract gets a balance equal to the amount of ether sent. How should this be done?

Here is how I am deploying the contract:

const fs = require("fs");
const solc = require('solc');
let Web3 = require('web3');
let web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
let go = fs.readFileSync('HoneyPot.sol').toString();
let compiledContract = solc.compile(go);
abiDefinition = JSON.parse(compiledContract.contracts[':HoneyPot'].interface);
contract = web3.eth.contract(abiDefinition);
byteCode = '0x'+compiledContract.contracts[':HoneyPot'].bytecode;
let gasEstimate = web3.eth.estimateGas({data: byteCode});

And finally the line that deploys it (without sending ether):

deployedContract = contract.new({from:web3.eth.accounts[0],data:byteCode,gas: gasEstimate+40000});

2 Answers 2


You can call HoneyPot function as follows:


Hope it helps~


Just add "value" to the line that deploys the contract.

deployedContract = contract.new({from:web3.eth.accounts[0], value: 5 wei, data:byteCode,gas: gasEstimate+40000});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.