I am trying to build a Dapp which includes functionality to deposit funds to a contract and withdraw them. The functions look like this

function fundContract() public payable {
        require (msg.sender == users[msg.sender].addr);
        users[msg.sender].balance += msg.value;


function withdraw (uint amount) public onlyUser() payable{

        require (msg.sender == users[msg.sender].addr);
        require (amount > 0);
        require (amount <= users[msg.sender].balance);


        users[msg.sender].balance -= amount;
        contractBalance-= amount;

I understand that there will be a function call to withdraw() specifying the amount parameter from the front end using web3.js send() command, but how do I provide the msg.value for the fundContract method from the viewpoint of a Dapp. Remix allows specifying the value in the message , but I can't find a way to do so for a Dapp.

  • 1
    Whatever library you're using, there will be a way to attach ether to a transaction. Let us know what library, and we can point you to the relevant documentation. Web3.js is a likely candidate for what you're going to use, and there are two significant versions: 0.20.x and 1.0 beta. – user19510 Sep 12 '18 at 17:10
  • @smarx I am building on Qtum and using QtumJS which is similar to web3.js The answer by Sam makes it clear how to use it with web3 and I found a similar way with QtumJS. Thank you – Siddhanjay Godre Sep 12 '18 at 17:43

You should use value field then call you contract send method


myContract.methods.fundContract().send({value: 'AMOUNT IN WEI'})

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.